1

In my angular 4 application I need to go in the same page with different routing param, for example I have:

  1. /ticketBundles/{id}
  2. /ticketBundles/new
  3. /ticketBundles/{id}/copy

Now when I am navigating I use this.router.navigate(path,id) In 2 and 3 I need to go in the same page but in a different "mode", In third case I need to load some data so what is the best practice to do that? Third path is a good path? If I use a path like /ticketBundles/copy/{id} I am following a good way?

1 Answer 1

1

It is recommended to follow RESTFUL programming. What exactly is RESTful programming?

So for example the closest you can get in your example would be..:

NEW (POST): /ticketBundle 
UPDATE (PUT): /ticketBundle/{id}
SHOW (GET): /ticketBundle/{id}

and for your copy i would do /ticketBundle/{id}/copy

You should take a look at the official docs for angular routing to help you 1. Navigate to a new page. 2. Pass in the params. 3. Retrieve the params on a new page.

https://angular.io/guide/router

In your routing module:

{ path: 'ticketBundle/:id', component: ticketComponent }

In your component

  this.router.navigate(['/ticketBundle', { id: ticketID}]);
Sign up to request clarification or add additional context in comments.

3 Comments

following /ticketBundle/{id}/copy how can I manage routing when I route to, and how to set code in my component
ok and in the /ticketBundle/{id}/copy routes how ca I manage it, I don't want to use query params because the path will be /ticketBundle;id={id};mode=copy
Why not use params? /ticketBundle/{id}/{mode}. This way you can check the mode param and depending on what it is such as copy, then carry out those functions

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.