diff --git a/.changeset/four-plants-happen.md b/.changeset/four-plants-happen.md new file mode 100644 index 0000000000..b273d8ec41 --- /dev/null +++ b/.changeset/four-plants-happen.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-sentry': patch +'@backstage/plugin-welcome': patch +--- + +Refactor route registration to remove deprecating code diff --git a/docs/reference/createPlugin.md b/docs/reference/createPlugin.md index 45e3303124..4a58a5ecdc 100644 --- a/docs/reference/createPlugin.md +++ b/docs/reference/createPlugin.md @@ -4,7 +4,7 @@ title: createPlugin description: Documentation on createPlugin --- -Taking a plugin config as argument and returns a new plugin. +Takes a plugin config as an argument and returns a new plugin. ## Plugin Config @@ -28,18 +28,22 @@ type PluginHooks = { ### Creating a basic plugin -Showcasing adding multiple routes, a feature flag and a redirect. +Showcasing adding a route and a feature flag. ```jsx -import { createPlugin } from '@backstage/core'; +import { createPlugin, createRouteRef } from '@backstage/core'; import ExampleComponent from './components/ExampleComponent'; +export const rootRouteRef = createRouteRef({ + path: '/new-plugin', + title: 'New Plugin', +}); + export default createPlugin({ id: 'new-plugin', register({ router, featureFlags }) { + router.addRoute(rootRouteRef, ExampleComponent); featureFlags.register('enable-example-component'); - - router.registerRoute('/new-plugin', ExampleComponent); }, }); ``` diff --git a/packages/core-api/src/plugin/types.ts b/packages/core-api/src/plugin/types.ts index 427d3d539a..855264c5f4 100644 --- a/packages/core-api/src/plugin/types.ts +++ b/packages/core-api/src/plugin/types.ts @@ -92,6 +92,7 @@ export type RouterHooks = { /** * @deprecated See the `addRoute` method + * @see https://github.com/backstage/backstage/issues/418 */ registerRoute( path: RoutePath, diff --git a/plugins/sentry/src/plugin.ts b/plugins/sentry/src/plugin.ts index 6b4080dd2b..fc4b1af5e0 100644 --- a/plugins/sentry/src/plugin.ts +++ b/plugins/sentry/src/plugin.ts @@ -14,12 +14,17 @@ * limitations under the License. */ -import { createPlugin } from '@backstage/core'; +import { createPlugin, createRouteRef } from '@backstage/core'; import SentryPluginPage from './components/SentryPluginPage'; +export const rootRouteRef = createRouteRef({ + path: '/sentry', + title: 'Sentry', +}); + export const plugin = createPlugin({ id: 'sentry', register({ router }) { - router.registerRoute('/sentry', SentryPluginPage); + router.addRoute(rootRouteRef, SentryPluginPage); }, }); diff --git a/plugins/welcome/src/plugin.ts b/plugins/welcome/src/plugin.ts index 945bf32c57..754f708110 100644 --- a/plugins/welcome/src/plugin.ts +++ b/plugins/welcome/src/plugin.ts @@ -14,14 +14,18 @@ * limitations under the License. */ -import { createPlugin } from '@backstage/core'; +import { createPlugin, createRouteRef } from '@backstage/core'; import WelcomePage from './components/WelcomePage'; +export const rootRouteRef = createRouteRef({ + path: '/welcome', + title: 'Welcome', +}); + export const plugin = createPlugin({ id: 'welcome', register({ router, featureFlags }) { - router.registerRoute('/welcome', WelcomePage); - + router.addRoute(rootRouteRef, WelcomePage); featureFlags.register('enable-welcome-box'); }, });