Using next(false) or next(error) while navigating to a component manually doesn't redirect to any component
See original GitHub issueVersion
3.1.3
Reproduction link
https://codesandbox.io/s/repro-history-yigiu?fontsize=14&hidenavigation=1&theme=dark"
Steps to reproduce
- Click in redirect with parameter, the variable will be passed to the component
- Click in redirect without parameter, the component will note that there’s no variable and will cancel the navigation
- Try manually navigating to the component “/query” and no component will render at all.
What is expected?
Redirection to the root (‘/’) component (it should be ‘Main’ in this case)
What is actually happening?
Redirection to an empty component (as the ‘from’ gives out an empty route)
I was trying to fetch some data from the backend, I needed a boolean flag from the server whether or not should I render this view at all, or just display some error message and handle the exception, calling next(new Error())
and handling the error accordingly with router.onError();
works when I’m accessing the component within the application, but doesn’t when I navigate manually to the component.
I can work around this just doing next(from.path)
, but it won’t trigger the .onError()
I mentioned earlier.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Next.js Redirect from / to another page - Stack Overflow
As @warfield pointed out in his answer from next.js >= 12.1 relative URLs are no longer allowed in redirects and using them will...
Read more >How to implement redirects in Next.js - LogRocket Blog
Redirects enable users to transfer an executed URL to a new URL to reroute an incoming request from one path to another.
Read more >next.config.js: Redirects
Redirects allow you to redirect an incoming request path to a different destination path. To use Redirects you can use the redirects key...
Read more >Common Routing Tasks - Angular
To create a component using the CLI, enter the following at the command line ... The Angular router selects this route any time...
Read more >ASP.NET Core Blazor routing and navigation - Microsoft Learn
Receives the RouteData from the Router along with any route parameters. Renders the specified component with its layout, including any further ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
check if
from.name === null
in the guardThis is intended because nothing is telling the application that it should go to the main route if the initial navigation fails, so it stays in a nowhere state which is the initial state of the router. The main route could also have navigation guards that should be checked. You need to trigger a navigation to the route you want to go in your specific case