question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't find routes that are spread into the Route config

See original GitHub issue

I have a fresh Angular application, with a routes.ts file and the following content:

export const routes: Routes = [
	{
		path: '',
		component: SiteFrameComponent,
		children: [
			{
				path: 'a',
				loadChildren: () => ...
			},
			{
				path: 'b',
				loadChildren: () => ...
			},
			{
				path: '404',
				component: NotFoundComponent,
			},
		],
	},
	{ path: '**', redirectTo: '/404' },
];

This is then imported in the AppModule into RouterModule.forRoot(routes)

This is pretty straightforward and common, and it works perfectly.

However, as soon as I want to move out some routes to a separate variable, and then spread it back into the config, scully can’t follow:

export const mainPages: Routes = [
	{
		path: 'a',
		loadChildren: () => ...,
	},
	{
		path: 'b',
		loadChildren: () => ...,
	},
];

export const routes: Routes = [
	{
		path: '',
		component: SiteFrameComponent,
		children: [
			...mainPages,
			{
				path: '404',
				component: NotFoundComponent,
			},
		],
	},
	{ path: '**', redirectTo: '/404' },
];

I separated some routes because I imported it elsewhere to render out links to these routes with an ngFor. So I would get new links by just adding a new route.

I get the following error from guess:

Finding all routes in application.
traversing app for routes
⠸ Loading guess-parser TypeError: Cannot read property 'values' of undefined
    at getObjectProp (<project-folder>/node_modules/guess-parser/dist/guess-parser/index.js:444:32)
    at Object.exports.readLoadChildren (<project-folder>/node_modules/guess-parser/dist/guess-parser/index.js:471:16)
    at Object.exports.getLazyEntryPoints (<project-folder>/node_modules/guess-parser/dist/guess-parser/index.js:400:26)
    at collectEntryPoints (<project-folder>/node_modules/guess-parser/dist/guess-parser/index.js:921:30)
    at Array.forEach (<anonymous>)
    at collectEntryPoints (<project-folder>/node_modules/guess-parser/dist/guess-parser/index.js:925:31)
    at visitTopLevelRoutes (<project-folder>/node_modules/guess-parser/dist/guess-parser/index.js:909:13)
    at visitNodes (<project-folder>/node_modules/typescript/lib/typescript.js:27858:30)
    at Object.forEachChild (<project-folder>/node_modules/typescript/lib/typescript.js:28032:24)
    at NodeObject.forEachChild (<project-folder>/node_modules/typescript/lib/typescript.js:146142:23)

Versions:

	"@angular/core": "11.2.12",
	"@scullyio/ng-lib": "^1.1.1",
	"@scullyio/scully": "^1.1.1",

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SanderEliascommented, May 4, 2021

@mgechev The question of @AlexAegis was: Why does this work:

export const mainPages: Routes = [
	{path: 'a',  loadChildren: ...	},
	{path: 'blog', loadChildren: ...	},
];

const otherPages: Routes = [
	{path: '404',  component: NotFoundComponent },
];

export const routes: Routes = [
	{
		path: '',
		component: SiteFrameComponent,
		children: mainPages.concat(otherPages),
	},
	{ path: '**', redirectTo: '/404' },
];

while this doesn’'t:

export const mainPages: Routes = [
	{path: 'a',  loadChildren: ...	},
	{path: 'blog', loadChildren: ...	},
];

const otherPages: Routes = [
	{path: '404',  component: NotFoundComponent },
];

export const routes: Routes = [
	{
		path: '',
		component: SiteFrameComponent,
		children: [...mainPages, ...otherPages, {path:'xxx', component: yyy}],
	},
	{ path: '**', redirectTo: '/404' },
];

Both of them seem to be statically analyzable?

0reactions
SanderEliascommented, May 14, 2021

given the answer from @mgechev

We can’t know what’s in the user’s localStorage. To simplify the parsing algorithm, we’re also not interpreting expressions in route definitions. There is nothing actionable left in here, so I’m going to close this

Read more comments on GitHub >

github_iconTop Results From Across the Web

All Routes in One File, not spread out across Modules. Is it ...
The mapping of a URL to a particular action is done using routes that are defined in the module's module.config.php file. Open your...
Read more >
Route configuration | OpenShift Container Platform 4.11
Path-based routes; Route-specific annotations; Configuring the route admission policy; Creating a route through an Ingress object; Creating a route using ...
Read more >
The Hitchhiker's Guide to React Router v4: the hidden value of ...
Welcome to the Hitchhiker's Guide to React Router v4, Part IV! ... This routes are coming from the route config array — got...
Read more >
Re-routing & Rearranging Existing Routes on a PCB in Altium ...
This page looks at modifying existing routing, either by rerouting or re-arranging. The former allows you to interactively place a fresh ...
Read more >
React Router v6 Preview
You don't need to use an exact prop on <Route path="/"> anymore. This is because all <Route> paths match exactly by default. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found