0

So I have a Back-End that's in charge of sending confirmation emails to users when they create an account, the email has a format like: http://localhost:8080/confirm?token=

I then want to have route with the same format on my Front-End side (which is made with Angular), so my question is how this url should be represented in my application routes. I'm currently trying to use { path: 'confirm', paramMap: { token : token } } but not sure this is the best way to handle this, this is my first time doing something like this so I'd appreciate any input :)

I later need to use that token value in a service so I need a way to obtain its value in the "confirm" component or something.

3
  • You don't include the parameters in the routing. If the component needs to access the query params, it can subscribe to them via the ActivatedRoute. I'd recommend reading angular.io/guide/router Commented Nov 3, 2017 at 17:44
  • Do you know of any example uses? Commented Nov 3, 2017 at 17:46
  • There are literally some in the documentation. That's what it's for. Commented Nov 3, 2017 at 18:10

2 Answers 2

2

I have an example of using query parameters here: https://github.com/DeborahK/MovieHunter-routing

As Jon stated, you don't specify query parameters in the route configuration:

enter image description here

UPDATE: Updated the screen shot to correct a typo and for latest syntax.

Sign up to request clarification or add additional context in comments.

Comments

1

Inject the ActivatedRoute in your Component constructor and then access params using ActivatedRoute instance.

    export class TestComponent Implements OnInit
    {
     token:string;
    constructor(private route:ActivatedRoute)
    {
    }
   ngOnInit()
   {
    route.params.subscribe((params:Params)=>{
      this.token=params['token'];
      //Or call your service to load the resource you need.
   })

   }
}

This is just sample example.

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.