- 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-Router Nested Routes
Description
You can define nested routes by defining the route within another route by passing a callback to the current route.
Syntax
Router.map(function() {
this.route('link-page', { path: 'pathTolinkpag' }, function() {
this.route('link-page');
});
});
Example
<!DOCTYPE html>
<html>
<head>
<title>Emberjs </title>
<!-- CDN's -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.1/handlebars.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.10.0/ember.min.js"></script>
<script src="https://builds.emberjs.com/tags/v1.10.0-beta.3/ember-template-compiler.js"></script>
<script src="https://builds.emberjs.com/release/ember.debug.js"></script>
<script src="https://builds.emberjs.com/beta/ember-data.js"></script>
</head>
<body>
<script type="text/x-handlebars">
<h2>Click the links to navigate</h2>
{{#linkTo 'index'}}index{{/linkTo}}
{{#linkTo 'description'}}description{{/linkTo}}
{{#linkTo 'description.fruits'}}description/fruits{{/linkTo}}
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<!-- default route -->
<h2>Fruits</h2>
</script>
<script type="text/x-handlebars" data-template-name="description/index">
<!-- this is description route
<h2>Description</h2 -->
<p>Fruits are helps to gain your strength.</p>
</script>
<script type="text/x-handlebars" data-template-name="description/fruits">
//fruits route is of the description route
<h2>Fruits Page</h2>
<ul>
<li>Orange</li>
<li>Apple</li>
<li>Banana</li>
</ul>
</script>
<script type="text/javascript">
App = Ember.Application.create();
App.Router.map(function() {
//nested routes: fruits within description
this.resource('description', function() {
this.route('fruits');
});
});
</script>
</body>
</html>
Output
Let's carry out the following steps to see how above code works:
Save above code in routing_nstd_rut.htm file
Open this HTML file in a browser.
Advertisements