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.

Router Cannot read property 'path' of undefined

See original GitHub issue
[ x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I am using mgechev seed to do some testing so I have a home routes and about routes

In my app component I am trying to navigate to the home route with this.router.navigate(['', {foo: 'bar'}]);

The issue is that this does not work as expected. If the user is currently on the about route this.router.navigate(['', {foo: 'bar'}]); will send them to /about;foo=bar, if the user is on the home route it produces the error Cannot read property 'path' of undefined

Expected/desired behavior

If the user is on the about route this.router.navigate(['', {foo: 'bar'}]); should send them to the home route with query params ;foo=bar. If the user is already on the home route it should just change the query params.

If the user is on the about route and wants to change the query params it should require this code instead this.router.navigate(['about', {foo: 'bar'}]); otherwise there is no way to navigate to the home route from the about route

What is the motivation / use case for changing the behavior? Being able to change the query params on a route with an empty path such as the home route in this example.

  • Angular version: 2.0.0-rc.4

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
raphaelluchinicommented, Apr 10, 2017

I’m having this issue too when I have children routes with same path as ‘’ and send parameters, for exemple:

export const routes = [
    { path:'', component: MainComponent, children: [{
                path: '', component: ChildComponent,
         }]
    }
];

<a [routerLink]="['./', {param:'value'}]">Link</a>

4reactions
dpalitacommented, Feb 12, 2017

@Andrey-Pavlov I ran into the exact same problem (converting existing routes to lazy-loaded ones), you helped me pinpoint it. It seems like you can’t put matrix parameters on a lazy-loaded route that has an emtpy path (‘’). I worked around it with (adapted to your example) …

export const routes = [
    { path:'', redirectTo: 'test', pathMatch: 'full'},
    { path: 'test', component: TestComponent }
];

… and now it does work. I don’t mind the extra path, but it might not be very meaningful in some situations.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Router: Cannot read property 'path' of undefined · Issue #22643
when error happens, startIndex is bigger than segmentGroup.segments.length , so p is undefined, p.path will be invalid. Seems segmentGroup.
Read more >
Fixing error: Cannot read property 'path' of undefined
is saying that no file has been able to be decoded by the the server. You have to make sure of 2 things:...
Read more >
Cannot read property 'path' of undefined - Cloudinary Support
I'm getting this error even though multer logged the correct req.file. [0] req.file: {“fieldname”:“src”,“originalname”:“Pexels Videos...
Read more >
TypeError: Cannot read property 'path' of undefined - Vue Forum
If I console log the current var, it shows undefined . So there seems to be an issue with getting the proper current...
Read more >
cannot read properties of undefined (reading 'path') nodejs
You're calling connectDB() which returns immediately (because it's async). You don't 'wait' until dbconnection is being set.
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