From 6fb4258a83588276fa5d5d18e83b3686d21a54c1 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 7 Mar 2021 23:23:55 +0100 Subject: [PATCH] changesets: added changeset for SubRoutes Signed-off-by: Patrik Oldsberg --- .changeset/heavy-lemons-hope.md | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .changeset/heavy-lemons-hope.md diff --git a/.changeset/heavy-lemons-hope.md b/.changeset/heavy-lemons-hope.md new file mode 100644 index 0000000000..7a47ec3644 --- /dev/null +++ b/.changeset/heavy-lemons-hope.md @@ -0,0 +1,41 @@ +--- +'@backstage/core-api': patch +--- + +Add `SubRouteRef`s, which can be used to create a route ref with a fixed path relative to an absolute `RouteRef`. They are useful if you for example have a page that is mounted at a sub route of a routable extension component, and you want other plugins to be able to route to that page. + +For example: + +```tsx +// routes.ts +const rootRouteRef = createRouteRef({ id: 'root' }); +const detailsRouteRef = createSubRouteRef({ + id: 'root-sub', + parent: rootRouteRef, + path: '/details', +}); + +// plugin.ts +export const myPlugin = createPlugin({ + routes: { + root: rootRouteRef, + details: detailsRouteRef, + } +}) + +export const MyPage = plugin.provide(createRoutableExtension({ + component: () => import('./components/MyPage').then(m => m.MyPage), + mountPoint: rootRouteRef, +})) + +// components/MyPage.tsx +const MyPage = () => ( + + {/* myPlugin.routes.root will take the user to this page */} + }> + + {/* myPlugin.routes.details will take the user to this page */} + }> + +) +```