From 5c797e4f5376e294b2cbd77ef97655fdaff50635 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sun, 26 Apr 2020 14:30:58 +0200 Subject: [PATCH] packages/dev-utils: default to navigating to the first registered route --- packages/dev-utils/src/devApp/render.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/dev-utils/src/devApp/render.tsx b/packages/dev-utils/src/devApp/render.tsx index f39a1ebb0e..768e0973e6 100644 --- a/packages/dev-utils/src/devApp/render.tsx +++ b/packages/dev-utils/src/devApp/render.tsx @@ -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(, document.getElementById('root')); } @@ -145,6 +154,20 @@ class DevAppBuilder { return registry; } + + private findPluginPaths(plugins: BackstagePlugin[]) { + const paths = new Array(); + + 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