Angular 5 localize-router set route with country/lang 代码
Angular 5 localize-router set route with country/lang code
这是我的问题。我必须在 Angular 中设置路由,以便在 URL 中会有国家代码和语言。例如
https://example.com/usa/en
棘手的部分是这个本地化部分可以更改,所以我有一个按钮可以切换国家和语言,所以它将是 /gb/en 或 /usa/fr.
如何使用 localize-router 和 ngx-translate 使其像这样工作。
非常感谢任何帮助。
如果我问错了,请原谅,但如果我理解正确,你可以按照以下方法:
在您的 AppRoutingModule 中配置路由如下:
const routes: Routes = [
{
path:'' , pathMatch: 'full', component: SomeComponent,
children: [
{ path: ':country-code/:lang-code' , component: SomeOtherComponent }
]
}
]
您现在可以通过按钮点击事件进行重定向,它会相应地更改 country-code 和 lang-code,您可以检索这些SomeOtherComponent 中的值来执行相关任务。
这是我的问题。我必须在 Angular 中设置路由,以便在 URL 中会有国家代码和语言。例如
https://example.com/usa/en
棘手的部分是这个本地化部分可以更改,所以我有一个按钮可以切换国家和语言,所以它将是 /gb/en 或 /usa/fr.
如何使用 localize-router 和 ngx-translate 使其像这样工作。
非常感谢任何帮助。
如果我问错了,请原谅,但如果我理解正确,你可以按照以下方法:
在您的 AppRoutingModule 中配置路由如下:
const routes: Routes = [
{
path:'' , pathMatch: 'full', component: SomeComponent,
children: [
{ path: ':country-code/:lang-code' , component: SomeOtherComponent }
]
}
]
您现在可以通过按钮点击事件进行重定向,它会相应地更改 country-code 和 lang-code,您可以检索这些SomeOtherComponent 中的值来执行相关任务。