0

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.

0

3 Answers 3

1

You should be using it as params

let username = this.route.snapshot.params["username"]; 
Sign up to request clarification or add additional context in comments.

1 Comment

Happy to help you
1

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}

Comments

0

Try this :

this.route.snapshot.params['username']

Instead of queryParams

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.