index routes
/
tests : TestPage
applications : ApplicationPage
login: XPage (i added this for educational purposes)
/login : LoginPage
I have a similar router structure. /login goes to LoginPage instead of XPage. However, it says index route has the proirity over other router in documentation. Can you give me the logic of this case? And also the general logic of routing, if possible? @Tanner Linsley
10 Replies
eastern-cyan•3y ago
Index routes should not have children
You're probably wanting a layout route instead (use
id: 'some-name' instead of path: '/'quickest-silverOP•3y ago
yes i have an id with my index route but i don't remember why i added this. does it make any difference?
eastern-cyan•3y ago
I'll need to see your actual config
quickest-silverOP•3y ago


quickest-silverOP•3y ago
Actually this works well for me right now but I wondered why this works while reading the documentation.
eastern-cyan•3y ago
So, it works?
quickest-silverOP•3y ago
It does what I desire to do but I don't see why /login goes to LoginPage even if I create a new path "login" as a child of authenticatedRoute. If index route is first matched, second login should match.
Probably I'm missing something.
eastern-cyan•3y ago
The rule that fixes all of this is that
path: '/' routes should never have children
So / => login is an antipattern. Matching stops when it hits an index route (path: '/')
path: '/' literally means "match when my parent route is the last segment"quickest-silverOP•3y ago
I see, did you prohibit adding children to index route? Because I tried deleting the id of authenticatedRoute and application failed. That means my authenticatedRoute is not actually an index route since I added an id to it.(i don't even remember why i added but probably bacause demo examples also added). I think it is a pathless route.
eastern-cyan•3y ago
I didn't prohibit it per se (it won't error or anything)
Authenticated route should only have an ID, not a path
ID paths do not create nested path structure, so their children will be flattened up with its siblings
This is why:
- path: '/login'
- id: 'authed'
- path: '/login'
Doesn't work.
It will get flattened to this:
- path: '/login'
- path: '/login'