1

I am building a list app, where list-items can be selected. Only one item can be selected at a time. A detail-view for the list-item is displayed below the list.

Now I want to change the url based on which item is selected, without navigating to another page.

Is it possible? If yes, how?

Thanks

1

1 Answer 1

2

Use route parameters for this

{ path: '', redirectTo, 'items', pathMatch: 'full' },
{ path: 'items', component: ItemList, children: [
  { path: '', component: DummyItem },
  { path: ':id/detail', component: ItemDetails }
]}
<a [routerLink]="itemId + '/detail'">Item {{itemId}}</a>
class ItemDetail {
  constructor(route:ActivatedRoute) {
    route.params.subscribe(params => this.id = params['id']);
  }
}

With a router navigation, when only route params change, nothing is reloaded.

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

1 Comment

I have used the solution provided in the following answer, since it was easier to implement with what I have. In case of refactoring my code, I will use the approach you provided. Thanks. stackoverflow.com/questions/35618463/…

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.