You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/release/routing/defining-your-routes.md
+67-37Lines changed: 67 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ To define a route, run
8
8
ember generate route route-name
9
9
```
10
10
11
-
This creates a route file at `app/routes/route-name.js`, a template for the route at `app/templates/route-name.hbs`,
11
+
This creates a route file at `app/routes/route-name.js`, a template for the route at `app/templates/route-name.gjs`,
12
12
and a unit test file at `tests/unit/routes/route-name-test.js`.
13
13
It also adds the route to the router.
14
14
@@ -65,7 +65,7 @@ Router.map(function() {
65
65
```
66
66
67
67
The route defined above will by default use the `blog-post.js` route handler,
68
-
the `blog-post.hbs` template, and be referred to as `blog-post` in any
68
+
the `blog-post.gjs` template, and be referred to as `blog-post` in any
69
69
`<LinkTo />` components.
70
70
71
71
Multi-word route names that break this convention, such as:
@@ -77,7 +77,7 @@ Router.map(function() {
77
77
```
78
78
79
79
will still by default use the `blog-post.js` route handler and the
80
-
`blog-post.hbs` template, but will be referred to as `blog_post` in any
80
+
`blog-post.gjs` template, but will be referred to as `blog_post` in any
81
81
`<LinkTo />` components.
82
82
83
83
## Nested Routes
@@ -109,17 +109,22 @@ ember generate route posts/new
109
109
And then add the `{{outlet}}` helper to your template where you want the nested
110
110
template to display. You can also add a page title with the current page name (using [page-title helper](../../accessibility/page-template-considerations/#toc_page-title)), this will help users with assistive technology know where they are in the website.
111
111
112
-
```handlebars {data-filename=templates/posts.hbs}
113
-
{{page-title "Posts - Site Title"}}
114
-
<h1>Posts</h1>
115
-
{{!-- Display posts and other content --}}
116
-
{{outlet}}
112
+
```handlebars {data-filename=templates/posts.gjs}
113
+
import { pageTitle } from 'ember-page-title'
114
+
115
+
<template>
116
+
{{pageTitle "Posts - Site Title"}}
117
+
118
+
<h1>Posts</h1>
119
+
{{!-- Display posts and other content --}}
120
+
{{outlet}}
121
+
</template>
117
122
```
118
123
119
124
This generates a route for `/posts` and for `/posts/new`. When a user
120
-
visits `/posts`, they'll simply see the `posts.hbs` template. (Below, [index
125
+
visits `/posts`, they'll simply see the `posts.gjs` template. (Below, [index
121
126
routes](#toc_index-routes) explains an important addition to this.) When the
122
-
user visits `posts/new`, they'll see the `posts/new.hbs` template rendered into
127
+
user visits `posts/new`, they'll see the `posts/new.gjs` template rendered into
123
128
the `{{outlet}}` of the `posts` template.
124
129
125
130
A nested route name includes the names of its ancestors.
@@ -134,7 +139,7 @@ routes, it will load a template with the same name (`application` in
134
139
this case) by default.
135
140
You should put your header, footer, and any other decorative content
136
141
here. All other routes will render
137
-
their templates into the `application.hbs` template's `{{outlet}}`.
142
+
their templates into the `application.gjs` template's `{{outlet}}`.
138
143
139
144
This route is part of every application, so you don't need to
140
145
specify it in your `app/router.js`.
@@ -200,38 +205,51 @@ replace the `{{outlet}}` in the `posts` template with the
200
205
201
206
The following scenarios may help with understanding the `index` route:
202
207
203
-
- The top-level index route is analogous to `index.html`. For example, when someone visits `https://some-ember-app.com`, the contents of the `template/index.hbs` file will be rendered. There is no need to add an entry `this.route('index', { path: '/' });` in `app/router.js` file. The `index` route is implicitly included in order to help reduce verbose declarations in the `app/router.js`. The `app/router.js` file could be empty, and the `index` would still be shown:
208
+
- The top-level index route is analogous to `index.html`. For example, when someone visits `https://some-ember-app.com`, the contents of the `template/index.gjs` file will be rendered. There is no need to add an entry `this.route('index', { path: '/' });` in `app/router.js` file. The `index` route is implicitly included in order to help reduce verbose declarations in the `app/router.js`. The `app/router.js` file could be empty, and the `index` would still be shown:
204
209
205
210
```javascript {data-filename=app/router.js}
206
211
Router.map(function() {
207
212
});
208
213
```
209
-
- When a user navigates to `/posts`, the contents of `index.hbs` will be rendered. This is similar to a user navigating to the child route of `/posts`. `/posts/index` is a child route like `/posts/comments` or `/posts/likes`.
214
+
- When a user navigates to `/posts`, the contents of `index.gjs` will be rendered. This is similar to a user navigating to the child route of `/posts`. `/posts/index` is a child route like `/posts/comments` or `/posts/likes`.
210
215
211
216
### When to use an index route
212
217
213
218
The index route is most helpful for rendering a view when the route has [dynamic segments](#toc_dynamic-segments) defined in it or there are nested routes. In other words, an `index` template is used to show content that should not be present on sibling and child routes. For example, a blog app might have an `index` route that shows a list of all posts, but if a user clicks on a post, they should only see the content for the individual post. Here is how that looks in practice:
214
219
215
-
A `templates/posts.hbs` file has the following:
220
+
A `templates/posts.gjs` file has the following:
221
+
222
+
```handlebars {data-filename=templates/posts.gjs}
216
223
217
-
```handlebars {data-filename=templates/posts.hbs}
218
-
{{page-title "Posts"}}
219
-
<h1>This is the posts template, containing headers to show on all child routes</h1>
220
-
{{outlet}}
224
+
import { pageTitle } from 'ember-page-title'
225
+
226
+
<template>
227
+
{{pageTitle "Posts"}}
228
+
<h1>This is the posts template, containing headers to show on all child routes</h1>
229
+
{{outlet}}
230
+
</template>
221
231
```
222
232
223
-
The `templates/posts/index.hbs` file has the following:
233
+
The `templates/posts/index.gjs` file has the following:
Behind the scenes, what is happening is that the [route's controller](https://api.emberjs.com/ember/release/classes/Route/methods/setupController?anchor=setupController) receives the results of the model hook, and Ember makes the model hook results available to the template. Your app may not have a controller file for the route, but the behavior is the same regardless.
If you decide to pass the entire model, be sure to cover this behavior in your [application tests](../../testing/testing-application/).
241
253
242
254
If a route you are trying to link to has multiple dynamic segments, like `/photos/4/comments/18`, be sure to specify all the necessary information for each segment:
0 commit comments