question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using next(false) or next(error) while navigating to a component manually doesn't redirect to any component

See original GitHub issue

Version

3.1.3

Reproduction link

https://codesandbox.io/s/repro-history-yigiu?fontsize=14&hidenavigation=1&theme=dark"

Steps to reproduce

  1. Click in redirect with parameter, the variable will be passed to the component
  2. Click in redirect without parameter, the component will note that there’s no variable and will cancel the navigation
  3. 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
posvacommented, Jan 16, 2020

check if from.name === null in the guard

1reaction
posvacommented, Jan 16, 2020

This 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found