Fix: Improve route matching fallback and optimize imports in components.tsx
#538
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.
PR Checklist
Summary
This fixes related issues.
It prevents
routeMatch
from referencing invalid objects in nested routes on multiple paths.Before the 8b766a9 commit, there was no issue, but after applying that commit, the example in the issue has an error.
How did you test this change?
For example, on the following page, which is an extension of the issue source, the log collected when the button is triggered to navigate from
/
to/unauthenticated
is as follows.If there is no nested structure here,
routeMatches[i]
will find a matched object with the correct component, but as you enter deeper into the nested structure,routeMatches.length
decreases, therouteContext
that captured thei
in the upper for loop attempts to reference the undefinedrouteMatches[i]
, thus causing an error.Regarding the method for finding the correct
routeMatches
, we may consider optimizing the cachedRouteContext
,props.routerState.matches()
, or other related components.The current commit aims to normalize the behavior with minimal modifications.