【问题标题】:URL language code in ember.js routesember.js 路由中的 URL 语言代码
【发布时间】:2013-07-02 17:24:43
【问题描述】:

是否可以使用 ember.js 在 URL 中添加全局语言代码前缀?例如

/#/en/about
/#/de/about

换句话说

/#/{language_code}/whatever/is/there/...

【问题讨论】:

    标签: url localization ember.js routes url-routing


    【解决方案1】:

    当然,您可以像这样将路由嵌套在 lang 资源中。

    App.Router.map(function() {
      this.resource('lang', { path: '/:lang_id' }, function() {
        this.route('about');
      });
    });
    

    然后您可以使用带有{{linkTo}} 的路由,例如,

    {{#linkTo 'about' 'en'}}About (en){{/linkTo}}
    {{#linkTo 'about' 'de'}}About (de){{/linkTo}}
    

    【讨论】:

    • 如何访问lang_id 来设置I18n.locale
    • params.lang_id 在对应的model 钩子中LangRoute
    • @DarshanSawardekar 所以不需要在 linkTo helper 的第一个参数中添加 lang.about ?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 2013-05-17
    • 2012-11-25
    • 2021-02-20
    • 2020-03-09
    • 2012-03-21
    • 2018-07-18
    相关资源
    最近更新 更多