您可以通過將回調(diào)傳遞到當(dāng)前路由來(lái)定義另一個(gè)路由中的路由來(lái)定義嵌套路由。
Router.map(function() { this.route('link-page', { path: 'pathTolinkpag' }, function() { this.route('link-page'); }); });
<!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>
讓我們執(zhí)行以下步驟,看看上面的代碼如何工作:
將上面的代碼保存在routing_nstd_rut.html文件中
在瀏覽器中打開此HTML文件。
更多建議: