Best way to share logic between parallel routes

I have forget-password (/forget-password) and reset-password (/reset-password/:token) route. They share some logic but their urls are not nested. Thus, I cannot use parent route to define those shared logic.

Would create a route with those shared logic and inherit it to create forget-password and reset-password routes be the best way to share logic here?

You could define a “virtual” route PasswordRoute and let both extend that object.

Don’t know abut best way. Another way is to create a mixin that you include in both. I personally prefer that.

1 Like

Can you point me to a “virtual” route example?

virtual is just a description; just declare it like a normal route

// non ES6 syntax

// this route doesn't actually exist in your router
// it serves as ancestor for the two real routes
App.PasswordRoute = Ember.Route.extend({
   // shared logic ...

});

App.ForgetPasswordRoute = App.PasswordRoute.extend({
   // specific logic
});

App.ResetPasswordRoute = App.PasswordRoute.extend({
   // specific logic
});

I learned something. Thanks!

Another simple option (maybe better) is to put your shared code in a Mixin (see @rainerfrey’s answer in this thread.)