fix: other routers except the first one fails to match in some scenes #123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1 Problem
In some cases, when defining multi
router
s, only the first router get matched, the others are invalid.Code to confirm problem:
Visit
localhost:3000/test
, will get a 404 response. And the logs:2 Course
After some work of debug, I found the problem:
In
dispatch()
method (middleware), It will setlayer.path
toctx.routerPath
, for the example above, it's/.*/
(RegExp), Then, the secondrouter
get the value,path
becomes/.*/
, but it should be/test
which the request carries with.3 More
This piece of code comes from #93 , which tries to fix #34 . I invested the issue, I think maybe the behavior before the fix has no problem, it should be the intended action. Maybe this needs more discussion.
The last thing, this PR breaks a test case, which tests
ctx.routerPath
should exists.