Skip to content

Commit

Permalink
fix route collision with extensions (#8861)
Browse files Browse the repository at this point in the history
* fix route collision with extensions

* revert type change

---------

Co-authored-by: Alexandre Alves <[email protected]>
  • Loading branch information
aalves08 and Alexandre Alves authored May 18, 2023
1 parent 113e1d3 commit 57c0e69
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions shell/core/plugin-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,39 @@ export class PluginRoutes {
// Using the existing router and adding routes to it will force nuxt middleware (specifically authenticated on default layout) to
// execute many times (nuxt middleware boils down to router.beforeEach). This issue was seen refreshing in a harvester cluster with a
// dynamically loaded cluster
const newRouter: Router = new Router({
mode: 'history',
routes: allRoutes
});

const pluginRoutesWithParents: any[] = [];
const orderedPluginRoutes: any[] = [];

// separate plugin routes that have parent and not
newRoutes.forEach((r: any) => {
let foundParentRoute;

if (r.parent) {
newRouter.addRoute(r.parent, r.route);
} else {
newRouter.addRoute(r.route);
foundParentRoute = allRoutes.find(route => route.name === r.parent);

if (foundParentRoute) {
pluginRoutesWithParents.push(r);
}
}

if (!foundParentRoute) {
orderedPluginRoutes.push(r.route);
}

this.pluginRoutes.push(r.route);
});

const newRouter: Router = new Router({
mode: 'history',
routes: [...orderedPluginRoutes, ...allRoutes]
});

// handle plugin routes with parent
pluginRoutesWithParents.forEach((r: any) => {
newRouter.addRoute(r.parent, r.route);
});

// Typing is incorrect
(this.router as any).matcher = (newRouter as any).matcher;
}
Expand Down

0 comments on commit 57c0e69

Please sign in to comment.