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.

Feature request: Route guards

See original GitHub issue

I’d like to see some form of route guards added, this would check for a truthy statement before attempting to load the component.

This would be useful, with server side guards for the initial load, as when using Link’s route attribute it does not reload the page.

Ideal example usage:

const routes = module.exports = require('next-routes')();

const guard = function(route) {

    // Check JWT tokens
    // ...etc
    return true;
}

// Singular guards
routes.add('/', 'index').guard(guard);

// Multiple guards
routes.add('/', 'index').guard([guard, guard]);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fridayscommented, Jul 30, 2018

I think getInitialProps is the best place to do this to have it work on both server and client routing

0reactions
dextermbcommented, Mar 5, 2019

@dextermb Hey is there any reason this was closed? Did you figure out how to guard? Looking to do exit intent popup when a user abandons cart.

EDIT: I see in the docs it can be done. https://nextjs.org/docs/#intercepting-popstate

I closed it as I used getInitialProps as suggested by @fridays. While I still would like to see this feature added, I’ll probably end up doing it in my own fork as this repository doesn’t seem to be very active.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature Request] Object based route guards #44 - GitHub
This works just fine for allowing a single object to declare the route guards and the redirect, however it still falls short as...
Read more >
How To Use Angular Route Guards As Feature Toggles
They enable the developer to carry out some logic when a user requests a route, and then allow or deny the user access...
Read more >
Route Guards in React - JavaScript in Plain English
Route Guard is a mechanism to have more control over the routes that are available throughout your app. These can be simple menu...
Read more >
Angular Authentication: Using Route Guards | by Ryan Chenkie
Angular's route guards are interfaces which can tell the router whether or not it should allow navigation to a requested route.
Read more >
Common Routing Tasks - Angular
The last route with the path of ** is a wildcard route. The router selects this route if the requested URL doesn't match...
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