You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am running into an issue with a guard that redirects to the same path.
What I'd like to do in the guard is to check if the route was called without a search query parameter.
If that's the case, a default search query parameter is applied and next.redirect(samePath?param=new) is invoked.
Steps to reproduce
Basic example:
constrequireViewParameter=(to: GuardToRoute,_from: GuardFunctionRouteProps|null,next: Next)=>{constquery=to.location.search;if(query.length>0){returnnext();}console.log('No id was was set, redirecting to the default view');next.redirect({
...to.location,search: `?id=1`,});};<GuardProviderguards={[requireViewParameter]}><GuardedRouteexactpath={'view'}component={View}/></GuardProvider>
Open the application and set the path to /view without any query parameters
Expected result
The guard runs and the URL is updated to /view?id=1
Actual result
The guard runs and invokes the redirect, but the new query parameter is not applied. The app stays on /view instead.
Environment
OS: Windows 10
Browser and its version: Chrome Canary 99.0.4819.0 (Official Build) 64-bit
React Router DOM version:
"react": "17.0.2"
"react-router-dom": "5.3.0"
"react-router-guards": "^1.0.2"
The text was updated successfully, but these errors were encountered:
Description
I am running into an issue with a guard that redirects to the same path.
What I'd like to do in the guard is to check if the route was called without a search query parameter.
If that's the case, a default search query parameter is applied and
next.redirect(samePath?param=new)
is invoked.Steps to reproduce
Basic example:
Open the application and set the path to
/view
without any query parametersExpected result
The guard runs and the URL is updated to
/view?id=1
Actual result
The guard runs and invokes the redirect, but the new query parameter is not applied. The app stays on
/view
instead.Environment
The text was updated successfully, but these errors were encountered: