Repository navigation
Replies: 1 comment
|
This isn't a bug, it's how the v6 ranking algorithm scores these two routes, and the dynamic route legitimately wins. Why Route matching in v6 doesn't pick the "more literal" branch, it computes a numeric score for every matching branch and takes the highest. The scoring lives in
Running the actual function on your two routes:
Both routes match In v5 this didn't happen because matching was more order/first-match dependent; v6 replaced that with this scoring and ranking system from its initial release, so routes that used to "just work" by declaration order can now lose to a more specific-looking sibling. Fixes
<Route path="/dashboard">
<Route path="channels/:id" element={<Dashboard />} />
{/* ...other known dashboard sub-routes */}
</Route>A route like
|
Uh oh!
There was an error while loading. Please reload this page.
I'm unable to understand whats going on here and whether this is a bug. This scenario is quite simple, and was working fine in v5, but not in v6. After hours of debugging Ive narrowed to just this:
Given 2 routes likes this:
/dashboard/channelswill render<Dashboard />✅/dashboard/channels/1will render<SomePage />❌How can # 2 path match the 2nd route when there is an exact match with "dashboard" in the 1st router. The whole point of /* is to match anything that comes after it, as given in https://reactrouter.com/6.30.1/route/route#splats
When I remove the 2nd route, then # 2 path matches the 1st route.
All reactions