# Best way to share logic between parallel routes

**URL:** <https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341>\
**Category:** Uncategorized\
**Created:** [February 17, 2015, 4:42pm UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341 "2015-02-17T16:42:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![daiweilu](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/daiweilu/32/10347_2.png) [@daiweilu](https://discuss.emberjs.com/u/daiweilu)\
**Post date:** [February 17, 2015, 4:42pm UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341/1 "2015-02-17T16:42:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![splattne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/splattne/32/3694_2.png) [@splattne](https://discuss.emberjs.com/u/splattne)\
**Post date:** [February 18, 2015, 9:28am UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341/2 "2015-02-18T09:28:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rainerfrey](https://avatars.discourse-cdn.com/v4/letter/r/d07c76/32.png) [@rainerfrey](https://discuss.emberjs.com/u/rainerfrey)\
**Post date:** [February 18, 2015, 12:23pm UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341/3 "2015-02-18T12:23:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [February 19, 2015, 6:35am UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341/4 "2015-02-19T06:35:19Z")

</div>

> [@splattne](#):
>
> “virtual” route

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

---

<div class="post-metadata">

**Author:** ![splattne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/splattne/32/3694_2.png) [@splattne](https://discuss.emberjs.com/u/splattne)\
**Post date:** [February 20, 2015, 9:40am UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341/5 "2015-02-20T09:40:51Z")

</div>

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
});

```

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [February 20, 2015, 9:59am UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341/6 "2015-02-20T09:59:14Z")

</div>

I learned something. Thanks!

---

<div class="post-metadata">

**Author:** ![splattne](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/splattne/32/3694_2.png) [@splattne](https://discuss.emberjs.com/u/splattne)\
**Post date:** [February 20, 2015, 10:07am UTC](https://discuss.emberjs.com/t/best-way-to-share-logic-between-parallel-routes/7341/7 "2015-02-20T10:07:31Z")

</div>

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

- [Mixin - 4.6 - Ember API Documentation](http://emberjs.com/api/classes/Ember.Mixin.html)

- [http://www.kaspertidemann.com/mixins-in-ember-js/](http://www.kaspertidemann.com/mixins-in-ember-js/)

- [In ember.js, what's the difference between mixin and extend? - Stack Overflow](http://stackoverflow.com/questions/13539102/in-ember-js-whats-the-difference-between-mixin-and-extend)
