Make hasPathChanged on the Guard component configurable#39
Open
glennverschooren wants to merge 1 commit intoUpstatement:mainfrom
Open
Make hasPathChanged on the Guard component configurable#39glennverschooren wants to merge 1 commit intoUpstatement:mainfrom
glennverschooren wants to merge 1 commit intoUpstatement:mainfrom
Conversation
beahuang
suggested changes
Dec 4, 2020
| [routePrevProps, routeProps], | ||
| ); | ||
| const hasPathChanged = useMemo(() => { | ||
| if (pathChanged && typeof pathChanged === 'function') { |
Contributor
There was a problem hiding this comment.
It'd be more clear if we named this variable checkPathChanged so you know from a glance it should be a function
|
|
||
| export type PropsWithMeta<T> = T & { | ||
| meta?: Meta; | ||
| pathChanged?: ( |
Contributor
There was a problem hiding this comment.
Instead of adding the type here, we'll want to add it to the GuarderRoute and GuardProps below
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The parent route will rerender (destroy and initialize) each time the user navigates between child routes.
This can cause issues when fetching data inside a container/parent component or when the parent component must hold some state because the component will lose his current state each time the user navigates between the child routes.
Therefore I thought it will be a good idea to make the
hasPathChangedfunction configurable so the developer can choose when the guards of the parent should be called.Example:
Navigate to /users => check user guards
Navigate from /users to /users/123 => don't check the /user guards (don't destroy the /users route)
Navigate from /users/123 to /users/overview => don't check the /user guards (don't destroy the /users route)
What this does
It will allow the developer to set his own
hasPathChangedfunction.