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.

feat(router): implement otherwise/routeNotFound hook

See original GitHub issue

We need some way to deal with the following cases:

  • Route doesn’t match
  • CanActivate returns false
  • CanDeactivate returns false

This might not all be implemented the same way.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
electricBonfirecommented, Feb 15, 2016

New to the Party, and Angular2, But I am also looking for an implementation as described by @janneromell

If a user types in any URL, and is not authenticated. I interpreted CanActivate as a place to check for if authenticated and if not return false. However, I would also like to redirect the user to a login page when this happens. (Note: not using this for “real” security, more as a view filter. Data is secured by server).

1reaction
Krustie101commented, Oct 11, 2015

I do not think the “is authenticated” check should be done in the CanActivate handler. It is not the concern of the CanActivate handler of a specific component. And you would have to put it on every component that is a routing target. And how would you distinguish between a “no data present” and a “not authenticated” event?

In the ui-router you have a stateChangeStart event. A similar concept seems to be missing in the angular 2 router, maybe for good reasons? After all, it is already possible to listen to “navigation finish” events.

But I would be wary of giving access to the Router service in a handler (CanActivate or startNavigation handler) in order to change the routing, this could get tricky. At first glance, it seems cleaner if such a navigationStart handler should be able to return something that the router resolves to a new (navigation) Instruction that overrides the original one in exceptional case like an authentication check.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Hooks with React Router - LogRocket Blog
In this tutorial, you can learn how to use Hooks with React Router and minimize code lines in a component.
Read more >
Invoke hook from React Router data router action
As configuration and action are now outside of a functional component, I cannot make use of the useAuthentication hook. My configuration looks ...
Read more >
React Hook Router - GitHub
The flexible, and fast router for react that is entirely based on ... Detailed documentation about how to use hookrouter can be found...
Read more >
useLoaderData v6.6.0 - React Router
This hook provides the value returned from your route loader. import { createBrowserRouter, RouterProvider, useLoaderData, } from "react-router-dom"; ...
Read more >
Verizon Router User Guide
QoS support (end to end layer 2/3) featuring: Differentiated ... C. Connect the power cord to your router then to an electrical outlet....
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