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?

Alessandro Celeghin
  • 3,161
  • 9
  • 42
  • 82

1 Answers1

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}]);
Kay
  • 11,044
  • 31
  • 100
  • 173
  • following `/ticketBundle/{id}/copy` how can I manage routing when I route to, and how to set code in my component – Alessandro Celeghin Oct 09 '17 at 10:53
  • 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` – Alessandro Celeghin Oct 09 '17 at 11:38
  • 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 – Kay Oct 09 '17 at 13:15