Reputation: 14145
My goal is to fetch username from a url
Inside app.routing I have route
export const routes: Routes = [
{ path: 'dashboard/:username', component: App }
];
inside appp component I'm trying to fetch this username using
let username = this.route.snapshot.queryParams["username"];
My browser is using localhost:91/dashboard/john
username is always undefined
.
Upvotes: 0
Views: 33
Reputation: 2698
Try this :
this.route.snapshot.params['username']
Instead of queryParams
Upvotes: 0
Reputation: 48357
You don't need to use queryParams
here. This is useful when you have something like this:
localhost:91/dashboard?username=john
Just use params
property.
this.route.snapshot.params["username"];
I suppose you declared route in following way:
{ path: 'dashboard/:username', component: SomeComponent}
Upvotes: 1
Reputation: 41573
You should be using it as params
let username = this.route.snapshot.params["username"];
Upvotes: 1