Reputation: 307
I want to see an user's username as part of URL. For example:
I have an URL like this:
www.undefiend.com/panel/dashboard
I want to customize it for every user. Like this:
www.undefiend.com/user1/dashboard
or
www.undefiend.com/michael/mails
or
www.undefiend.com/richard/profile
an others...
How can I do that in Angular 2 or above ?
Any helps would be great. Thanks for help.
Upvotes: 3
Views: 2836
Reputation: 657118
Use the router with a param in the route
routes = [
{ path: ':user', children: [
{ path: 'dashboard', component: DashboardComponent, }
]},
{ path: '**', component: 'LoginComponent' }
];
And in the login component you then navigate to the route with the user
this.router.navigate(['/' + username, 'dashboard']);
See also https://angular.io/docs/ts/latest/guide/router.html#!#can-activate-guard
Upvotes: 7