As described above, the route object calls a sequence of functions, starting with beforeModel. This function is a good place to check the state of the application before retrieving data. It is also a good place to reroute a user who cannot be on a page, such as to check for user authentication.
You will use beforeModel to unconditionally
transition the user to a new page. The
IndexRoute
is a good place to do this. You may
want to add a dashboard in the future, but for now the landing
page will be sightings
.
In app/routes/index.js, add a beforeModel callback:
import Ember from 'ember'; export default Ember.Route.extend({ beforeModel(){ this.transitionTo('sightings'); } });
Now, when you navigate to http://localhost:4200/ the URL changes to http://localhost:4200/sightings, and you should see the sightings list from app/templates/sightings/index.hbs.
The last two routing hooks, afterModel and
setupController, will not be used in Tracker.
When creating a route
file, you are cloning the
Ember.Route
object and overwriting the method,
much like an interface in languages like Java. The
setupController hook will run by default to set
the model property on the route object’s
controller
.
At this point, your application has some basic routes that outline its
functionality: a landing page, a list of
sightings, and a route for adding a new sighting. You created
templates for your routes and added model data to the
sightings
route. You rerouted the index route
to the sightings index. You are off to a great start!
In the next chapter, you will learn about
Ember.Model
s, adapters, computed properties,
and storage mechanisms.
3.137.176.166