Skip to content

Commit

Permalink
Document routes API (#6604)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Piercy <web@stevepiercy.com>
  • Loading branch information
sneridagh and stevepiercy authored Jan 22, 2025
1 parent 5c88b0b commit cfb6782
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type ConfigData = {
widgets: WidgetsConfig | Record<string, never>;
addonReducers?: AddonReducersConfig;
addonRoutes?: AddonRoutesConfig;
routes?: Array<ReactRouterRouteEntry>;
slots: SlotsConfig | Record<string, never>;
components: ComponentsConfig | Record<string, never>;
utilities: UtilitiesConfig | Record<string, never>;
Expand Down
55 changes: 55 additions & 0 deletions packages/registry/docs/how-to-guides/register-routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
myst:
html_meta:
"description": "How to register new routes in @plone/registry"
"property=og:description": "How to register new routes in @plone/registry"
"property=og:title": "How to register new routes in @plone/registry"
"keywords": "Volto, Plone, frontend, React, configuration, routes, React Router"
---

# Register new routes

The `config.registerRoute` method adds a route to the configuration registry.
It saves the routes in the `config.routes` key in the configuration object.
You should provide one route at a time.
Each route must have the following data shape.

```ts
type ReactRouterRouteEntry = {
type: 'route' | 'index' | 'layout' | 'prefix';
path: string;
file: string;
options?: {
id?: string;
index?: boolean;
caseSensitive?: boolean;
};
children?: ReactRouterRouteEntry[];
};
```

The `type`, `path`, and `file` are mandatory.
The `type` key specifies the route type to create, specifically one of `route`, `index`, `layout`, or `prefix`.
The type `route` can contain nested routes.

```{info}
The routes registered with this method must be compliant with React Router 7 routes.
They are loaded by a helper provided by `@plone/react-router` in an existing React Router 7 app.
Check the official [React Router 7 documentation](https://reactrouter.com/start/framework/routing) for more information on how to define React Router 7 routes.
```

Register a route as shown in the following example.

```ts
config.registerRoute({
type: 'route',
path: '/login',
file: '@plone/cmsui/components/login.tsx',
options: {
id: 'login',
index: true,
},
});
```

You must set the module's full path name of the registered route component to make `@plone/registry` correctly address it.
3 changes: 2 additions & 1 deletion packages/registry/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ myst:
"description": "@plone/registry provides support for building an add-on and configuration registry with infrastructure for JavaScript and TypeScript-based apps."
"property=og:description": "@plone/registry provides support for building an add-on and configuration registry with infrastructure for JavaScript and TypeScript-based apps."
"property=og:title": "@plone/registry"
"keywords": "@plone/registry, registry, add-on, configuration, component, utility, JavaScript, TypeScript, app"
"keywords": "@plone/registry, registry, add-on, configuration, component, routes, React Router, utility, JavaScript, TypeScript, app"
---

# `@plone/registry`
Expand All @@ -29,6 +29,7 @@ how-to-guides/access-registry
how-to-guides/register-and-retrieve-components
how-to-guides/register-and-retrieve-utilities
how-to-guides/shadow-a-component
how-to-guides/register-routes
```


Expand Down
1 change: 1 addition & 0 deletions packages/registry/news/6604.documentation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document the route API. @sneridagh

0 comments on commit cfb6782

Please sign in to comment.