fix(router-core): keep match.pathname consistent across nested matches with param parsing#7747
Conversation
…s with params.parse A route's params.parse result was written back into the shared routeParams object used to interpolate match.pathname for every route in the match chain, so a parent route's parsed param leaked into the pathname of routes matched after it. Keep routeParams raw for pathname interpolation and accumulate parsed params separately for match.params.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughModifies route matching logic in router-core to track parsed strict params separately from raw params via a new accumulatedStrictParams map, propagating parsed ancestor values down the match chain for consistent match.params. Adds a regression test verifying params/pathname consistency for nested routes using params.parse/stringify. ChangesStrict Param Propagation Fix
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
match.pathnameis inconsistent across nested matches whenparams.parse/params.stringifyare used: a parent route keeps the raw value in its own pathname, but its parsed value leaks into child routes' pathnames.In
matchRoutesInternal(packages/router-core/src/router.ts), each match's pathname is built withinterpolatePathfrom a single sharedrouteParamsobject. After building a route's pathname,Object.assign(routeParams, strictParams)wrote that route'sparams.parseresult back into the same shared object, which is then used to interpolate the child routes' pathnames.This keeps
routeParamsraw for allinterpolatePathcalls and accumulates parsed params separately (accumulatedStrictParams), used only formatch.params. Parsed-param inheritance semantics are preserved.Added a
match-params.test.tscase asserting pathname consistency across nested matches with parse/stringify. It fails without the fix and passes with it. router-core plus the react/solid/vue router downstream suites pass, tsc clean.Closes #7731
Summary by CodeRabbit
Bug Fixes
Tests