Merge pull request #24777 from backstage/rugvip/binding-backport
core-*-api: backport support for external route ref default targets + config route binding
This commit is contained in:
@@ -274,6 +274,21 @@ Note that we are not importing and using the `RouteRef`s directly in the app, an
|
||||
|
||||
Another thing to note is that this indirection in the routing is particularly useful for open source plugins that need to provide flexibility in how they are integrated. For plugins that you build internally for your own Backstage application, you can choose to use direct imports or even concrete route path strings directly. Although there can be some benefits to using the full routing system even in internal plugins: it can help you structure your routes, and as you will see further down it also helps you manage route parameters.
|
||||
|
||||
### Default Targets for External Route References
|
||||
|
||||
It is possible to define a default target for an external route reference, potentially removing the need to bind the route in the app. This reduces the need for configuration when installing new plugins through providing a sensible default. It is of course still possible to override the route binding in the app.
|
||||
|
||||
The default target uses the same syntax as the route binding configuration, and will only be used if the target plugin and route exist. For example, this is how the catalog can define a default target for the create component external route in a way that removes the need for the binding in the previous example:
|
||||
|
||||
```tsx title="plugins/catalog/src/routes.ts"
|
||||
import { createExternalRouteRef } from '@backstage/frontend-plugin-api';
|
||||
|
||||
export const createComponentExternalRouteRef = createExternalRouteRef({
|
||||
// highlight-next-line
|
||||
defaultTarget: 'scaffolder.createComponent',
|
||||
});
|
||||
```
|
||||
|
||||
### Optional External Route References
|
||||
|
||||
It is possible to define an `ExternalRouteRef` as optional, so it is not required to bind it in the app.
|
||||
|
||||
@@ -325,6 +325,33 @@ concrete routes directly. Although there can be some benefits to using the full
|
||||
routing system even in internal plugins. It can help you structure your routes,
|
||||
and as you will see further down it also helps you manage route parameters.
|
||||
|
||||
You can also use static configuration to bind routes, removing the need to make
|
||||
changes to the app code. It does however mean that you won't get type safety
|
||||
when binding routes and compile-time validation of the bindings. Static
|
||||
configuration of route bindings is done under the `app.routes.bindings` key in
|
||||
`app-config.yaml`. It works the same way as [route bindings in the new frontend system](../frontend-system/architecture/07-routes.md#binding-external-route-references),
|
||||
for example:
|
||||
|
||||
```yaml
|
||||
app:
|
||||
routes:
|
||||
bindings:
|
||||
bar.headerLink: foo.root
|
||||
```
|
||||
|
||||
### Default Targets for External Route References
|
||||
|
||||
Following the `1.28` release of Backstage you can now define default targets for
|
||||
external route references. They work the same way as [default targets in the new frontend system](../frontend-system/architecture/07-routes.md#default-targets-for-external-route-references),
|
||||
for example:
|
||||
|
||||
```ts
|
||||
export const createComponentExternalRouteRef = createExternalRouteRef({
|
||||
// highlight-next-line
|
||||
defaultTarget: 'scaffolder.createComponent',
|
||||
});
|
||||
```
|
||||
|
||||
### Optional External Routes
|
||||
|
||||
When creating an `ExternalRouteRef` it is possible to mark it as optional:
|
||||
|
||||
Reference in New Issue
Block a user