--- title: Use Route Templates with Co-located Syntax impact: MEDIUM-HIGH impactDescription: Better code organization and maintainability tags: routes, templates, gjs, co-location --- ## Use Route Templates with Co-located Syntax Use co-located route templates with modern gjs syntax for better organization and maintainability. **Incorrect (separate template file - old pattern):** ```glimmer-js // app/routes/posts.js (separate file) import Route from '@ember/routing/route'; export default class PostsRoute extends Route { model() { return this.store.request({ url: '/posts' }); } } // app/templates/posts.gjs (separate template file) Posts {{#each @model as |post|}} {{post.title}} {{/each}} ``` **Correct (co-located route template):** ```glimmer-js // app/routes/posts.gjs import Route from '@ember/routing/route'; export default class PostsRoute extends Route { model() { return this.store.request({ url: '/posts' }); } Posts {{#each @model as |post|}} {{post.title}} {{/each}} {{outlet}} } ``` **With loading and error states:** ```glimmer-js // app/routes/posts.gjs import Route from '@ember/routing/route'; import { service } from '@ember/service'; export default class PostsRoute extends Route { @service store; model() { return this.store.request({ url: '/posts' }); } Posts {{#if @model}} {{#each @model as |post|}} {{post.title}} {{/each}} {{/if}} {{outlet}} } ``` **Template-only routes:** ```glimmer-js // app/routes/about.gjs About Us Welcome to our application! ``` Co-located route templates keep route logic and presentation together, making the codebase easier to navigate and maintain. Reference: [Ember Routes](https://guides.emberjs.com/release/routing/)
Welcome to our application!