
- EmberJS - Home
- EmberJS - Overview
- EmberJS - Installation
- EmberJS - Core Concepts
- Creating and Running Application
- EmberJS - Object Model
- EmberJS - Router
- EmberJS - Templates
- EmberJS - Components
- EmberJS - Models
- EmberJS - Managing Dependencies
- EmberJS - Application Concerns
- EmberJS - Configuring Ember.js
- EmberJS - Ember Inspector
EmberJS - Redirecting
This is a URL redirection or forwarding mechanism, that makes a web page available for more than one URL address. Ember.js defines a transitionTo() method moves the application into another route and it behaves like link-to helper.
To redirect from one route to another route, define the beforeModel hook into the route handler.
Syntax
Ember.Route.extend ({ beforeModel() { this.transitionTo('routeToName'); } });
Example
The example given below depicts how to redirect from one route to another. Create a new route and name it as beforemodel and open the router.js file with the following code to define URL mappings −
Open the file beforemodel.js created under app/routes/ with the following code −
Open the file beforemodel.hbs created under app/templates/ with the following code −
Output
Run the ember server and you will receive the following output −
