-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fix(router): pop to previous route with params #24315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
995076d
to
cb16a4c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a couple thoughts, but I trust your judgment on whether changes actually need to be made; I might be misunderstanding the logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the Object.keys
change, this PR looks good. Can we also change the commit subject to be something more descriptive? Maybe something like fix(router): popping route now accounts for route params
.
Might be good to have the issue author verify the fix in their app if they have not already.
Great job!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto 👍
cb16a4c
to
8bcbbaa
Compare
const pathWithParams = routeIdParams.map(key => `:${key}`); | ||
for (let j = 0; j < pathWithParams.length; j++) { | ||
// Skip results where the path variable is not a match | ||
if (pathWithParams[j].toLowerCase() !== routeChain.path[j]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this assume that all segments of routeChain.path[j]
are parameter (i.e. :param
) ?
Would it work if some of the segments are fixed string ? (i.e. /fixed/:s1/:s2
)
@sean-perkins Is the test app shown in the "Other information" section of the PR description available somewhere ? Shouldn't it be added as an e2e test ? |
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
The function used to determine the correct path to resolve for
ion-router
does not take route parameters into consideration. It only compares the route ids, with the first definition always taking priority over all other routes. This means that if a router has multiple routes sharing the same component, the first definition will always be the route that is determined when running the matching algorithm.i.e.:
/
will always resolve as the path when determining the route to navigate to when going back tomy-page
component.Issue Number: Resolves #24223
What is the new behavior?
When calculating the best matched route in the chain, routes that both match the active route's id (page component match) and match the definition of route params will be weighted higher.
Does this introduce a breaking change?
Other information
The behavior before this PR (URL resets on pop or back interaction):
Kapture.2021-12-02.at.22.10.15.mp4
The behavior after this PR:
Kapture.2021-12-02.at.22.07.51.mp4