Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用angular2路由器使用不同的参数重新加载当前状态_Angular_Angular Routing - Fatal编程技术网

使用angular2路由器使用不同的参数重新加载当前状态

使用angular2路由器使用不同的参数重新加载当前状态,angular,angular-routing,Angular,Angular Routing,下面是我的路由器的一个示例: { path: ':lang', component: MainComponent children: [ {path: 'page1', component, children}, {path: 'page2', component, children}, ... ] }, URL中可能的变体示例如下: /en/page1 /es/page1/child 正如您所看到的,第一个参数是la

下面是我的路由器的一个示例:

{
    path: ':lang',
    component: MainComponent
    children: [
      {path: 'page1', component, children},
      {path: 'page2', component, children},
      ...
    ]
  },
URL中可能的变体示例如下:

  • /en/page1
  • /es/page1/child
正如您所看到的,第一个参数是
lang
,它表示页面的语言,之后它只是指向子页面的路径

我需要创建一个链接,该链接将重新加载当前状态,但使用不同的参数(在我的情况下为语言),如下所示:
/en/path/to/child/page
->
/es/path/to/child/page

对我来说最困难的部分是:

我不想在
[routherLink]
中硬编码
/path/to/child/page
,它应该是动态的。可能取自
ActivatedRoute
,但我还没有找到一种方法

它应该是一个链接,像这样的
西班牙语
不是控制器中的一个方法,像:
这个.router.navigate(…)
this.path = '/path/to/child/page';
使另一部分是动态的

<a [routerLink]="[lang, path]">{{lang}}</a>
{{lang}
在管线中指定路径

/:lang/path/to/child/page

像这样

this.path = '/path/to/child/page';
使另一部分是动态的

<a [routerLink]="[lang, path]">{{lang}}</a>
{{lang}
在管线中指定路径


/:lang/path/to/child/page

如果所有url都是使用相同的命名约定生成的-第一个url部分是您的语言-您可以使用下一个解决方案:

您的链接将如下所示:

<a [routerLink]="['en', getContentUrl()]">Documents</a>

如果您的所有url都是使用相同的命名约定生成的-第一个url部分是您的语言-您可以使用下一个解决方案:

您的链接将如下所示:

<a [routerLink]="['en', getContentUrl()]">Documents</a>

这就是重点,我需要
/:lang/
之后的所有内容都是动态的。抱歉,我没有提到这一点,我需要
/:lang/
之后的所有内容都是动态的。对不起,我没提