0

Suppose I have a component which displays the list of actors for a movie. After an actor is selected, some details about that particular actor will be displayed on the same component.

My goal is to include the movie id and actor id in the URL. Also, when a new actor is selected, the actor id from the URL should change accordingly.

The URL should have the following form: /movies/movieId/actors/actorId

So I have one component which will need to do the following:

  1. get the movie id
  2. for that movie id, get the list of actors
  3. if no actor id was supplied, select the first actor and modify the URL accordingly
  4. if an actor id was supplied, select that actor and don't modify the URL
  5. modify the actorId from the URL whenever the user selects an actor from the list

I'm not exactly sure what is the best solution for updating a URL parameter. At the moment, I'm using the following solution:

routing configuration:

path: ':movieIdId',
      component: MoviesComponent,
      children: [
        {
          path: 'actors',
          component: ActorsComponent
        },
        {
          path: 'actors/:actorId',
          component: ActorsComponent
        }
]

And for updating the URL I do the following:

updateActorId(actorId: number) {
    this.router.navigate(['movies', this.movieId, 'actors', actorId]);
}

1 Answer 1

1

One way of changing the URL without actually navigating somewhere else (if that's what you're asking about) is using Location go

location.go('/movies/' + this.moveId + '/actors/' + actorId)

https://angular.io/api/common/Location#go

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

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.