-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Open
Labels
fixed on 4.xThis issue has been already fixed on the v4 but exists in v3This issue has been already fixed on the v4 but exists in v3
Description
What problem does this feature solve?
The matcher implementation always use path-to-regex lib. It is too much for static paths, where it is possible to just compare strings.
Also, the implementatioin is O(N), if you have 100 routes and want to match the last one (that is static), you run 100 regex tests.
Regex is around ~10x slower than a simple string match and with a lookup table it is O(1).
vue-router/src/create-matcher.js
Lines 85 to 89 in 5d7afbe
for (let i = 0; i < pathList.length; i++) { | |
const path = pathList[i] | |
const record = pathMap[path] | |
if (matchRoute(record.regex, location.path, location.params)) { | |
return _createRoute(record, location, redirectedFrom) |
What does the proposed API look like?
The API don't change, it is just optimization.
I did a draft PR #3707 to show the idea.
Metadata
Metadata
Assignees
Labels
fixed on 4.xThis issue has been already fixed on the v4 but exists in v3This issue has been already fixed on the v4 but exists in v3