--- 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) ``` **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' }); } } ``` **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' }); } } ``` **Template-only routes:** ```glimmer-js // app/routes/about.gjs ``` 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/)