Note that there are some explanatory texts on larger screens.

plurals
  1. PORestrict access to specific routes in Ember.js (Ember.Router)
    primarykey
    data
    text
    <p>I'm currently testing <code>Ember.Router</code> and I'm wondering how I could restrict access to some specific routes when matching a certain criteria. In my example I'm playing with a checkout process where the billing address must be set before the user can proceed to the billing method and so on (for example: the billing method view needs to know the billing country to provide its allowed payment methods).</p> <p>In my attempt I'm trying to validate the model (serialize : function () or maybe enter : function () ?) and when the given value isn't set, the router should redirect to a previous state (had to do this with a little timeout, otherwise the hash won't get updated correctly).</p> <p>Here's a fiddle with my example code</p> <p><a href="http://jsfiddle.net/mediastuttgart/uMKGt/" rel="nofollow noreferrer">http://jsfiddle.net/mediastuttgart/uMKGt/</a></p> <p><strong>EDIT:</strong></p> <p>Found some words by tom dale, though not related to this question but still a good answer: "The entire point of states is to avoid situations like this ... It is the responsibility of the current state to handle them.".</p> <p>cf. <a href="http://github.com/emberjs/ember.js/issues/745" rel="nofollow noreferrer">http://github.com/emberjs/ember.js/issues/745</a></p> <p>Well this makes sense.</p> <p><strong>EDIT2:</strong></p> <p>Though this makes sense while the location method is set to 'null'. When using 'hash' or 'history' to handle location states and the user reloads the page on a deeper route than /index - the current route must validate the values and then eventually redirect to a previous one if a certain criteria does not match (while indeed the validation belongs to the previous route).</p> <p>To cut a long story short, the current route validation should depend on the previous one and should redirect to a state when all conditions are met.</p> <p>Reverse order:</p> <ul> <li>delivery method? (/#/delivery/method) nope -></li> <li>billing method? (/#/billing/method) nope -></li> <li>delivery address? (/#/delivery/address) nope -></li> <li>billing address - (/#/billing/address) please start here.</li> </ul> <p>Looking forward to see some EmberJS folks to clear things up :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload