vuejs / router

🚦 The official router for Vue.js
https://router.vuejs.org/
MIT License
3.88k stars 1.18k forks source link

fix: combining 'end' and 'strict' #2154

Open skirtles-code opened 7 months ago

skirtles-code commented 7 months ago

This Playground illustrates the problem:

The bottom row is the one that isn't working correctly. This combination of options:

{
  path: '/user/',
  strict: true,
  end: false,
  component: ...
}

should match the location path /user/1, but it doesn't.

The reason why is the RegExp is checking for the / twice:

^/user/(?:/|$)

While I've added a lot of extra testing for end: false, only two of those assertions would have failed with the previous code. Specifically, this one on line 666:

matchParams('/home/', '/home/other', {}, options)

and this one on line 673:

matchParams('/home/:p/', '/home/a/b', { p: 'a' }, options)

In both cases they would previously have failed to resolve the route.

netlify[bot] commented 7 months ago

Deploy Preview for vue-router canceled.

Name Link
Latest commit efc026e56f468ee4137ff5248966cd128c314413
Latest deploy log https://app.netlify.com/sites/vue-router/deploys/65e99c58b9ed150008af83fe
codecov-commenter commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.90%. Comparing base (13303bd) to head (4fce5c0).

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2154 +/- ## ======================================= Coverage 90.90% 90.90% ======================================= Files 24 24 Lines 1121 1121 Branches 347 347 ======================================= Hits 1019 1019 Misses 63 63 Partials 39 39 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.