There are still some questions and really now infos about the new angular2 router.
First off, there are no 'name' in the new @Routes, so there should be always relative URL paths, and that's okay.
But how can I check which is my activated route?? In the deprecated router I did this:
let instruction = this.router.generate(['Login']);
let isLoginRoute = this.router.isRouteActive(instruction);
the other thing is, Which is the best way to check if user has permissions to navigate to route. What is the best practice for it, until now I did something like that:
@CanActivate((next: ComponentInstruction, previous: ComponentInstruction) => {
return isLoggedIn(next, previous);
})
export class DashboardCmp implements OnDestroy {
...
export const isLoggedIn = (next: ComponentInstruction, previous: ComponentInstruction) => {
let injector: Injector = appInjector(); // get the stored reference to the injector
let router: Router = injector.get(Router);
let http: Http = injector.get(Http);
// return a boolean or a promise that resolves a boolean
return new Promise((resolve) => {
http
.get('/orma/api/v1/users/current')
.map(res => res.json())
.subscribe(
(userData) => {
console.log('ok, we got user data', userData);
resolve(true);
},
(err) => {
console.log('authentication failed, redirecting');
router.navigate(['/login']);
resolve(false);
});
});
};
can someone gives me an example for do all this in new angular2 router?
thx