packages/dev-utils: default to navigating to the first registered route
This commit is contained in:
@@ -86,6 +86,15 @@ class DevAppBuilder {
|
||||
// Build and render directory to #root element
|
||||
render(): void {
|
||||
const DevApp = this.build();
|
||||
|
||||
const paths = this.findPluginPaths(this.plugins);
|
||||
|
||||
if (window.location.pathname === '/') {
|
||||
if (!paths.includes('/') && paths.length > 0) {
|
||||
window.location.pathname = paths[0];
|
||||
}
|
||||
}
|
||||
|
||||
ReactDOM.render(<DevApp />, document.getElementById('root'));
|
||||
}
|
||||
|
||||
@@ -145,6 +154,20 @@ class DevAppBuilder {
|
||||
|
||||
return registry;
|
||||
}
|
||||
|
||||
private findPluginPaths(plugins: BackstagePlugin[]) {
|
||||
const paths = new Array<string>();
|
||||
|
||||
for (const plugin of plugins) {
|
||||
for (const output of plugin.output()) {
|
||||
if (output.type === 'route') {
|
||||
paths.push(output.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(rugvip): Figure out patterns for how to allow in-house apps to build upon
|
||||
|
||||
Reference in New Issue
Block a user