Skip to content

Commit 9d1b806

Browse files
committed
start converting a couple route files
1 parent f6e4ac9 commit 9d1b806

File tree

3 files changed

+113
-70
lines changed

3 files changed

+113
-70
lines changed

guides/release/routing/defining-your-routes.md

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To define a route, run
88
ember generate route route-name
99
```
1010

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`,
1212
and a unit test file at `tests/unit/routes/route-name-test.js`.
1313
It also adds the route to the router.
1414

@@ -65,7 +65,7 @@ Router.map(function() {
6565
```
6666

6767
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
6969
`<LinkTo />` components.
7070

7171
Multi-word route names that break this convention, such as:
@@ -77,7 +77,7 @@ Router.map(function() {
7777
```
7878

7979
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
8181
`<LinkTo />` components.
8282

8383
## Nested Routes
@@ -109,17 +109,22 @@ ember generate route posts/new
109109
And then add the `{{outlet}}` helper to your template where you want the nested
110110
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.
111111

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>
117122
```
118123

119124
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
121126
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
123128
the `{{outlet}}` of the `posts` template.
124129

125130
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
134139
this case) by default.
135140
You should put your header, footer, and any other decorative content
136141
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}}`.
138143

139144
This route is part of every application, so you don't need to
140145
specify it in your `app/router.js`.
@@ -200,38 +205,51 @@ replace the `{{outlet}}` in the `posts` template with the
200205

201206
The following scenarios may help with understanding the `index` route:
202207

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:
204209

205210
```javascript {data-filename=app/router.js}
206211
Router.map(function() {
207212
});
208213
```
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`.
210215

211216
### When to use an index route
212217

213218
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:
214219

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}
216223
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>
221231
```
222232

223-
The `templates/posts/index.hbs` file has the following:
233+
The `templates/posts/index.gjs` file has the following:
234+
235+
```handlebars {data-filename=templates/posts/index.gjs}
236+
import { pageTitle } from 'ember-page-title'
224237
225-
```handlebars {data-filename=templates/posts/index.hbs}
226-
{{page-title "Posts"}}
227-
<p>This is the posts/index template with a list of posts</p>
238+
<template>
239+
{{pageTitle "Posts"}}
240+
<p>This is the posts/index template with a list of posts</p>
241+
</template>
228242
```
229243

230-
The `templates/posts/post.hbs` file has the following:
244+
The `templates/posts/post.gjs` file has the following:
231245

232-
```handlebars {data-filename=templates/posts/post.hbs}
233-
{{page-title "Post"}}
234-
<p>This is an individual post, from the posts/post template, used when we enter the /posts/:post_id route</p>
246+
```handlebars {data-filename=templates/posts/post.gjs}
247+
import { pageTitle } from 'ember-page-title'
248+
249+
<template>
250+
{{pageTitle "Post"}}
251+
<p>This is an individual post, from the posts/post template, used when we enter the /posts/:post_id route</p>
252+
</template>
235253
```
236254

237255
This is equivalent to having the following entry in `app/router.js` file
@@ -247,18 +265,26 @@ Router.map(function() {
247265

248266
When the user navigates to `/posts/123`, the following markup will be seen:
249267

250-
```handlebars {data-filename=templates/posts/post.hbs}
251-
{{page-title "Posts"}}
252-
<h1>This is the posts template, containing headers to show on all child routes</h1>
253-
<p>This is an individual post, from the posts/post template, used when we enter the /posts/:post_id route</p>
268+
```handlebars {data-filename=templates/posts/post.gjs}
269+
import { pageTitle } from 'ember-page-title'
270+
271+
<template>
272+
{{pageTitle "Posts"}}
273+
<h1>This is the posts template, containing headers to show on all child routes</h1>
274+
<p>This is an individual post, from the posts/post template, used when we enter the /posts/:post_id route</p>
275+
</template>
254276
```
255277

256278
When the user navigates to `/posts/`, the following markup will be seen:
257279

258-
```handlebars {data-filename=templates/posts/index.hbs}
259-
{{page-title "Posts"}}
260-
<h1>This is the posts template, containing headers to show on all child routes</h1>
261-
<p>This is the posts/index template with a list of posts</p>
280+
```handlebars {data-filename=templates/posts/index.gjs}
281+
import { pageTitle } from 'ember-page-title'
282+
283+
<template>
284+
{{pageTitle "Posts"}}
285+
<h1>This is the posts template, containing headers to show on all child routes</h1>
286+
<p>This is the posts/index template with a list of posts</p>
287+
</template>
262288
```
263289

264290
## Dynamic Segments
@@ -322,9 +348,13 @@ Router.map(function() {
322348
});
323349
```
324350

325-
```handlebars {data-filename=app/templates/not-found.hbs}
326-
{{page-title "Not found"}}
327-
<p>Oops, the page you're looking for wasn't found</p>
351+
```handlebars {data-filename=app/templates/not-found.gjs}
352+
import { pageTitle } from 'ember-page-title'
353+
354+
<template>
355+
{{pageTitle "Not found"}}
356+
<p>Oops, the page you're looking for wasn't found</p>
357+
</template>
328358
```
329359

330360
In the above example we have successfully used a wildcard route to handle all routes not managed by our application

guides/release/routing/rendering-a-template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ the `posts.new` route will render `posts/new.hbs`.
1616

1717
Each template will be rendered into the `{{outlet}}` of its parent route's
1818
template. For example, the `posts.new` route will render its template into the
19-
`posts.hbs`'s `{{outlet}}`, and the `posts` route will render its template into
20-
the `application.hbs`'s `{{outlet}}`.
19+
`posts.gjs`'s `{{outlet}}`, and the `posts` route will render its template into
20+
the `application.gjs`'s `{{outlet}}`.

guides/release/routing/specifying-a-routes-model.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ export default class FavoritePostsRoute extends Route {
5555

5656
Now that data can be used in the `favorite-posts` template:
5757

58-
```handlebars {data-filename=app/templates/favorite-posts.hbs}
59-
{{#each @model as |post|}}
60-
<div>
61-
{{post.title}}
62-
</div>
63-
{{/each}}
58+
```handlebars {data-filename=app/templates/favorite-posts.gjs}
59+
<template>
60+
{{#each @model as |post|}}
61+
<div>
62+
{{post.title}}
63+
</div>
64+
{{/each}}
65+
</template>
6466
```
6567

6668
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.
@@ -133,22 +135,24 @@ export default class SongsRoute extends Route {
133135
In the `songs` template, we can specify both models and use the `{{#each}}` helper to display
134136
each record in the song model and album model:
135137

136-
```handlebars {data-filename=app/templates/songs.hbs}
137-
<h1>Playlist</h1>
138+
```handlebars {data-filename=app/templates/songs.gjs}
139+
<template>
140+
<h1>Playlist</h1>
138141
139-
<ul>
140-
{{#each @model.songs as |song|}}
141-
<li>{{song.name}} by {{song.artist}}</li>
142-
{{/each}}
143-
</ul>
142+
<ul>
143+
{{#each @model.songs as |song|}}
144+
<li>{{song.name}} by {{song.artist}}</li>
145+
{{/each}}
146+
</ul>
144147
145-
<h1>Albums</h1>
148+
<h1>Albums</h1>
146149
147-
<ul>
148-
{{#each @model.albums as |album|}}
149-
<li>{{album.title}} by {{album.artist}}</li>
150-
{{/each}}
151-
</ul>
150+
<ul>
151+
{{#each @model.albums as |album|}}
152+
<li>{{album.title}} by {{album.artist}}</li>
153+
{{/each}}
154+
</ul>
155+
</template>
152156
```
153157

154158
## Dynamic Models
@@ -216,31 +220,40 @@ instead.
216220
When you provide a string or number to the `<LinkTo>`, the dynamic segment's `model` hook will run when the app transitions to the new route.
217221
In this example, `photo.id` might have an id of `4`:
218222

219-
```handlebars {data-filename=app/templates/photos.hbs}
220-
{{#each @model as |photo|}}
221-
<LinkTo @route="photo" @model={{photo.id}}>
222-
link text to display
223-
</LinkTo>
224-
{{/each}}
223+
```handlebars {data-filename=app/templates/photos.gjs}
224+
import { LinkTo } from '@ember/routing';
225+
226+
<template>
227+
{{#each @model as |photo|}}
228+
<LinkTo @route="photo" @model={{photo.id}}>
229+
link text to display
230+
</LinkTo>
231+
{{/each}}
232+
</template>
225233
```
226234

227235
However, if you provide the entire model context, the model hook for that URL segment will _not_ be run.
228236
For this reason, many Ember developers choose to pass only ids to `<LinkTo>` so that the behavior is consistent.
229237

230238
Here's what it looks like to pass the entire `photo` record:
231239

232-
```handlebars {data-filename=app/templates/photos.hbs}
233-
{{#each @model as |photo|}}
234-
<LinkTo @route="photo" @model={{photo}}>
235-
link text to display
236-
</LinkTo>
237-
{{/each}}
240+
```handlebars {data-filename=app/templates/photos.gjs}
241+
import { LinkTo } from '@ember/routing';
242+
243+
<template>
244+
{{#each @model as |photo|}}
245+
<LinkTo @route="photo" @model={{photo}}>
246+
link text to display
247+
</LinkTo>
248+
{{/each}}
249+
</template>
238250
```
239251

240252
If you decide to pass the entire model, be sure to cover this behavior in your [application tests](../../testing/testing-application/).
241253

242254
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:
243255

256+
TODO(locks)
244257
```handlebars
245258
<LinkTo @route="photos.photo.comments.comment" @models={{array 4 18}}>
246259
link text to display

0 commit comments

Comments
 (0)