Angular 5 localize-router set route with country/lang 代码

标签 angular routing localization angular2-routing url-routing

这是我的问题。我必须在 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-codelang-code,您可以在SomeOtherComponent< 中检索这些值/strong> 执行相关任务。

关于Angular 5 localize-router set route with country/lang 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52000741/

相关文章:

Angular 6 - 使用 ng-content 时样式不起作用

angular - 每次使用 Angular 4 更改数组时触发动画

forms - 如果字段为空, Angular 形式禁用提交按钮

php - 如何强制 https 用于 prod 但 http 用于开发环境?

asp.net mvc 使用 html5mode 和路由托管 Angular 应用程序

iphone - 将新字符串添加到 iOS 中的可本地化字符串文件

angular - karma测试时如何打印log

php - Symfony2 中的路由

javascript - Vue i18n - 如何在 i18n 组件选项中获取当前语言环境?

iphone - 在头文件中使用变量和常量定义进行本地化