From c33b642daa2a21528c12068abdca81ffced261c7 Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Mon, 22 Jun 2015 16:22:34 -0700 Subject: [PATCH] Documents resetNamespace: true for nested routes which supersedes this.resource() emberjs/ember.js#11517 --- source/routing/defining-your-routes.md | 90 ++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/source/routing/defining-your-routes.md b/source/routing/defining-your-routes.md index 3b6dce226..05e6ffb4a 100644 --- a/source/routing/defining-your-routes.md +++ b/source/routing/defining-your-routes.md @@ -198,6 +198,96 @@ Visiting `/posts` is slightly different. It will first render the Finally, visiting `/posts/new` will first render the `posts` template, then render the `posts/new` template into its outlet. +#### Resetting Nested Route Namespace + +When nesting routes, it may be beneficial for a child route to not inherit its ancestors name. This allows you to reference and reuse a given route in multiple route trees as well as keep the class name short. This is equivalent to the behavior of the now deprecated `this.resource()` function. + +You can reset the current "namespace" with the aptly named `resetNamespace: true` option. + +```app/router.js +Router.map(function() { + this.route('post', { path: '/post/:post_id' }, function() { + this.route('edit'); + this.route('comments', { resetNamespace: true }, function() { + this.route('new'); + }); + }); +}); +``` + +This router creates five routes: + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
URLRoute NameControllerRouteTemplate
/indexapp/controllers/indexapp/routes/indexapp/templates/index
N/Apostapp/controllers/postapp/routes/postapp/templates/post
/post/:post_id2post.indexapp/controllers/post/indexapp/routes/post/indexapp/templates/post/index
/post/:post_id/editpost.editapp/controllers/post/editapp/routes/post/editapp/templates/post/edit
N/Acommentsapp/controllers/commentsapp/routes/commentsapp/templates/comments
/post/:post_id/commentscomments.indexapp/controllers/comments/indexapp/routes/comments/indexapp/templates/comments/index
/post/:post_id/comments/newcomments.newapp/controllers/comments/newapp/routes/comments/newapp/templates/comments/new
+
+ +2 `:post_id` is the post's id. For a post with id = 1, the route will be: +`/post/1` + +The `comments` template will be rendered in the `post` outlet. +All templates under `comments` (`comments/index` and `comments/new`) will be rendered in the `comments` outlet. + +The route, controller, and view class names for the comments resource are not prefixed with `Post`. + ### Multi-word Model Names For multi-word models all the names are camel cased except for the dynamic segment. For example, a model named `BigMac` would have a path of `/bigMacs/:big_mac_id`, route named `bigMac`, template named `bigMac`.