Aurelia-Router: changing route and address bar parameters from VM using a router

I want to update url-params in the address bar without routing. But I'm not sure how to do this with the Aurelia router from the view model.

In my case, I am sending identifiers in the url that receives the activated model activation method.

The route looks like this: http: // localhost: 3000 / # / test / products? 0 = 2599037842 & 1 = 2599080552

Then I want to remove the identifiers from the URL without reactivating the view model , for example, the result of the URL: http: // localhost: 3000 / # / test / products? 0 = 2599037842

Hope Aurelia-router has support

Thanks! / Mike

+7
aurelia aurelia-router
source share
1 answer

Yes, you can do this using the router.navigateToRoute() method. navigateToRoute has additional parameters. Use the options parameter (third) to change the way you navigate.

Example:

 import {inject} from 'aurelia-framework'; import {Router} from 'aurelia-router'; @inject(Router) export class Products { constructor(router) { this.router = router; } activate(params) { // TODO: Check your params here and do navigate according to values this.router.navigateToRoute( this.router.currentInstruction.config.name, // current route name { '0': params['0'] }, // route parameters object { trigger: false, replace: true } // options ); } } 

From the documentation center :

navigateToRoute(route: string, params?: any, options?: any): boolean

It will move to a new location that matches the specified route and parameters.

Params

  • route: string - the name of the route used to create the navigation location.
  • params?: any - route parameters that will be used when filling out the route template.
  • options?: any - Navigation options.

With options you control how the story is updated.

  • trigger: false - Prevents the launch of the router's navigation path.
  • replace: true - replaces the current URL in the history with the provided route (rewriting the history), so it will not start with browser feedback functions.
+16
source share

All Articles