packages/dev-utils: default to navigating to the first registered route

This commit is contained in:
Patrik Oldsberg
2020-04-26 14:30:58 +02:00
parent 6ab99a2052
commit 5c797e4f53
+23
View File
@@ -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