Reputation: 1008
In the routing, when we pass some value as paramters from one component to another, the passed parameters values gets appended to the browser url... is there any way it can be avoided?
In the example from snapshot attached "Administrator" is the username which I am passing from home.ts component
My routing is as follows
[![export const routes: RouterConfig = \[
{ path: '', component: Login },
{ path: 'login', component: Login },
{ path: 'Home/:userName', component: Home },
...HOME_ROUTER_PROVIDERS
}
\]
export const HOME_ROUTER_PROVIDERS: RouterConfig = \[
{
path: 'Home/:userName',
component: Home,
children: \[
{ path: 'Dashboard1', component: Dashboard1 },
{ path: 'Dashboard2', component: Dashboard2 },
....
}
\]][1]][1]
My home.ts where I do the navigate.route to pass the parameters
export class Home {
userName: any;
constructor(private activatedRoute: ActivatedRoute) {
console.log("In constructor of Home");
activatedRoute.params.subscribe(params => {
this.userName = params['userName']
});
}
}
Upvotes: 0
Views: 865
Reputation: 17894
you may create a UserService
using it in your Login component you may set some variable which decides if the logged in user is administrator or not.
And when your Home component is routed you may read role value from UserService
and do stuff using the value.
Upvotes: 2