Enforcing RouteRefs more: docs, templates, types
This commit is contained in:
@@ -14,12 +14,18 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createPlugin } from '@backstage/core';
|
||||
import { createPlugin, createRouteRef } from '@backstage/core';
|
||||
import ExampleComponent from './components/ExampleComponent';
|
||||
|
||||
export const rootRouteRef = createRouteRef({
|
||||
icon: () => null,
|
||||
path: '/{{ id }}',
|
||||
title: '{{ id }}',
|
||||
});
|
||||
|
||||
export const plugin = createPlugin({
|
||||
id: '{{ id }}',
|
||||
register({ router }) {
|
||||
router.registerRoute('/{{ id }}', ExampleComponent);
|
||||
router.addRoute(rootRouteRef, ExampleComponent);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -110,7 +110,7 @@ export class PrivateAppImpl implements BackstageApp {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'redirect-route': {
|
||||
case 'legacy-redirect-route': {
|
||||
const { path, target, options = {} } = output;
|
||||
const { exact = true } = options;
|
||||
routes.push(
|
||||
@@ -118,6 +118,19 @@ export class PrivateAppImpl implements BackstageApp {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'redirect-route': {
|
||||
const { from, to, options = {} } = output;
|
||||
const { exact = true } = options;
|
||||
routes.push(
|
||||
<Redirect
|
||||
key={from.path}
|
||||
path={from.path}
|
||||
to={to.path}
|
||||
exact={exact}
|
||||
/>,
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'feature-flag': {
|
||||
registeredFeatureFlags.push({
|
||||
pluginId: plugin.getId(),
|
||||
|
||||
@@ -42,12 +42,20 @@ export type RouterHooks = {
|
||||
options?: RouteOptions,
|
||||
): void;
|
||||
|
||||
addRedirect(from: RouteRef, to: RouteRef, options?: RouteOptions): void;
|
||||
|
||||
/**
|
||||
* @deprecated See the `addRoute` method
|
||||
*/
|
||||
registerRoute(
|
||||
path: RoutePath,
|
||||
Component: ComponentType<any>,
|
||||
options?: RouteOptions,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @deprecated See the `addRedirect` method
|
||||
*/
|
||||
registerRedirect(
|
||||
path: RoutePath,
|
||||
target: RoutePath,
|
||||
@@ -88,11 +96,24 @@ export class PluginImpl {
|
||||
options,
|
||||
});
|
||||
},
|
||||
addRedirect(from, to, options) {
|
||||
outputs.push({
|
||||
type: 'redirect-route',
|
||||
from,
|
||||
to,
|
||||
options,
|
||||
});
|
||||
},
|
||||
registerRoute(path, component, options) {
|
||||
outputs.push({ type: 'legacy-route', path, component, options });
|
||||
},
|
||||
registerRedirect(path, target, options) {
|
||||
outputs.push({ type: 'redirect-route', path, target, options });
|
||||
outputs.push({
|
||||
type: 'legacy-redirect-route',
|
||||
path,
|
||||
target,
|
||||
options,
|
||||
});
|
||||
},
|
||||
},
|
||||
featureFlags: {
|
||||
|
||||
@@ -41,6 +41,13 @@ export type RouteOutput = {
|
||||
|
||||
export type RedirectRouteOutput = {
|
||||
type: 'redirect-route';
|
||||
from: RouteRef;
|
||||
to: RouteRef;
|
||||
options?: RouteOptions;
|
||||
};
|
||||
|
||||
export type LegacyRedirectRouteOutput = {
|
||||
type: 'legacy-redirect-route';
|
||||
path: RoutePath;
|
||||
target: RoutePath;
|
||||
options?: RouteOptions;
|
||||
@@ -56,6 +63,7 @@ export type FeatureFlagOutput = {
|
||||
export type PluginOutput =
|
||||
| LegacyRouteOutput
|
||||
| RouteOutput
|
||||
| LegacyRedirectRouteOutput
|
||||
| RedirectRouteOutput
|
||||
| FeatureFlagOutput;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user