Route

Loads data and sets up state for a URL segment in the router map.

Since Ember 4/5 (Octane) Spec ↗

Syntax

class X extends Route { async model(params) {} }

Returns

Route — A route handler class.

Examples

import Route from '@ember/routing/route';
import { service } from '@ember/service';

export default class PostRoute extends Route {
  @service store;

  async model(params) {
    return this.store.findRecord('post', params.post_id);
  }
}
// app/router.js
Router.map(function () {
  this.route('post', { path: '/posts/:post_id' });
});

Notes

The model() hook resolves data before the template renders; its return value is available to the controller and template as @model. Use beforeModel/afterModel for redirects and setupController for extra state.