How to share code between new / edit routes?


#1

I’m frequently writing CRUD routes that duplicate a lot of code between the new and edit route. For example, if I’m rendering a “Project” select field in a form I typically want to load all projects in afterModel. In many cases, the only differences between the two routes are whether I create a new record or find an existing record.

Any recommendations on how to reduce this duplication?


#2

You can use Mixins, or perhaps create a base route and inherit from it. My choice would be to create a Mixin though.