jeudi 14 décembre 2017

Ember.js Wildcard URL

Any ember-way ideas to make a manual transition to a wildcard route with a dynamic segment at the end */:category_name, so I can manually build a "breadcrumbish url version" example, suppose a user enters to /banana I need to transition the user to /Groceries/Healthy/Fruit/Banana.... groceries, healthy, fruit might be entered as well so /Fruit would be transitioned to /Groceries/Healthy/Fruit... I was able to make it work using window.history.replaceState on the model hook of the route but strange enough it only works if it's being refreshed or type in by user, not while transitioning in template, thanks in advance guys

Route as is

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

Recap of cases:

Case 1:

User enters /products/banana

-Redirect to /products/groceries/healthy/fruit/banana

User enters /products/fruit

-Redirect to /products/groceries/healthy/fruit

Case 2:

User enters /products/groceries

-All good, it's correct.

Case 3

User enters /products/groceries/snacks

-doesn't exists so, 404 redirects.

All of this trouble is only for making a better UX for a new ecommerce I'm building, the normal suggested way is to just use one dynamic segment

Like

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

It's fair, but it's way nicer to build the breadcrumbish url

Again, thanks in advance




Aucun commentaire:

Enregistrer un commentaire