Using Angular2 to create a single page app, I\'m intercepting unauthenticated user access to non-public routes in a custom RouterOutlet
and redirecting them to
You might find what you need in the docs for the Location
class. The back()
function could possibly do it for you.
Another approach would be to subscribe to the popstate
events in Location
, instead. MDN has docs talking about the values you could expect to receive.
class MyCLass {
constructor(private location: Location) {
location.subscribe((val) => {
// do something with the state that's passed in
})
}
}
Otherwise you might want a service that tracks the changes in the Router so that you can access them.
class MyTrackingService {
constructor(private router: Router) {
router.subscribe((val) => {
// store the routes here so that you can peel them off as needed?
})
}
}
In this case I'm accessing the Router
object and subscribing to any changes so that I could track them.