Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document routes API #6604

Merged
merged 10 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/registry/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx_copybutton",
"sphinx_togglebutton", # Toggle admonitions in @plone/registry
"sphinxext.opengraph",
]

Expand Down
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
54 changes: 54 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,54 @@
---
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 and must have the following shape:
sneridagh marked this conversation as resolved.
Show resolved Hide resolved

```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 are intended to be React Router 7 compliant routes.
sneridagh marked this conversation as resolved.
Show resolved Hide resolved
They are meant to be loaded via a helper provided by `@plone/react-router` in an existing React Router 7 app.
sneridagh marked this conversation as resolved.
Show resolved Hide resolved
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
1 change: 1 addition & 0 deletions requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plone-sphinx-theme
sphinx-autobuild
sphinx-copybutton
sphinx-examples
sphinx-togglebutton
sphinxcontrib-video
sphinxcontrib-youtube
sphinxext-opengraph
Expand Down
Loading