はい、これはrouter.navigateToRoute()
メソッドで行うことができます。 navigateToRoute
には追加のパラメータがあります。 options
(3番目)パラメータを使用して、ナビゲーションの実行方法を変更します。
例:
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
);
}
}
documentation hubから:指定された経路とのparamsに対応する新たな位置へ
navigateToRoute(route: string, params?: any, options?: any): boolean
ナビゲートします。
PARAMS
route: string
- ナビゲーション位置を生成するときに使用するルートの名前。
params?: any
- ルートパターンを設定するときに使用するルートパラメータ。
options?: any
- ナビゲーションオプション。 options
で
あなたはどのようにhistory is updatedを制御します。
trigger: false
は -
replace: true
をトリガするために、ルータのナビゲーションパイプラインを防止 - それはブラウザバック機能
でトリガされませんので、提供ルート(歴史を書き換え)との歴史の中で現在のURLを置き換えます
素晴らしい作品 - ありがとう!私が見つけた改善の1つは、現在のルート名をプログラムで取得するために、 'products.-string'を「this.router.currentInstruction.config.name」に置き換えることでした。この変更をあなたの答えに加えることができます。 :) – Mike
素晴らしい。確かに、現在のルートに移動する必要がある場合は、それが機能します。回答は修正されました。 –