【问题标题】:Ember.js Wildcard URLEmber.js 通配符 URL
【发布时间】:2017-12-15 00:42:17
【问题描述】:

任何 ember-way 想法手动转换到末尾带有动态段的通配符路由 */:category_name,所以我可以手动构建一个“breadcrumbish url version”示例,假设用户输入 /banana I需要将用户转换为 /Groceries/Healthy/Fruit/Banana.... 杂货,健康,水果也可以输入,因此 /Fruit 将转换为 /Groceries/Healthy/Fruit... 我能够做到在路线的模型钩子上使用 window.history.replaceState 工作,但奇怪的是,它只有在用户刷新或输入时才有效,而不是在模板中转换时,提前谢谢大家

按原样路由

this.route('products', function(){
   this.route('wildcard_handler', {path: '*/:category_name'});
   this.route('handler', {path: '/:category_name'})
});

案例回顾:

案例一:

用户输入 /products/banana

-重定向到 /products/groceries/healthy/fruit/banana

用户输入 /products/fruit

-重定向到 /products/groceries/healthy/fruit

案例2:

用户输入 /products/杂货

-很好,没错。

案例 3

用户输入 /products/groceries/snacks

-不存在所以,404重定向。

所有这些麻烦只是为了为我正在构建的新电子商务提供更好的用户体验,通常建议的方法是只使用一个动态细分

喜欢

this.route('products', function(){
   this.route('handler', {path: '/:category_name'})
});

这很公平,但是构建面包屑网址会更好

再次感谢您

【问题讨论】:

    标签: javascript ember.js


    【解决方案1】:

    案例 1: 如果你想在解析模型之前将用户重定向到另一个路由,你可以使用beforeModel()钩子。您还可以使用redirect() 挂钩将用户重定向到另一条路线。例如(当用户访问/products/fruit,你可以将他们重定向到redirect钩子中的products/groceries/healthy/fruit),

    redirect(model, transition) {
       this._super(...arguments);
       this.transitionTo('products.groceries.healthy.fruit');
    }
    

    请参阅此link 以了解路由中的预定义挂钩。

    案例 3: 请参阅此 link 以了解您的应用程序中的通配符路由。

    【讨论】:

      猜你喜欢
      • 2013-08-18
      • 2021-07-01
      • 1970-01-01
      • 2012-04-28
      • 2019-03-03
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      相关资源
      最近更新 更多