Skip to content

Commit 82f97e5

Browse files
Geodewd549chriskrycho
authored andcommitted
DOCS: API: add routing helper examples
Let's add an example usage of all of the routing helpers (visit, currentRouteName, currentURL) to the API docs. (cherry picked from commit fa068a0)
1 parent 87dfbf4 commit 82f97e5

2 files changed

Lines changed: 30 additions & 4 deletions

File tree

API.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,20 @@ Navigate the application to the provided URL.
551551
* `url` **[string][64]** The URL to visit (e.g. `/posts`)
552552
* `options` **[object][72]** app boot options
553553

554+
#### Examples
555+
556+
Visiting the route for post 1.
557+
558+
```javascript
559+
await visit('/posts/1');
560+
```
561+
562+
Visiting the route for post 1 while also providing the `rootElement` app boot option.
563+
564+
```javascript
565+
await visit('/', { rootElement: '#container' });
566+
```
567+
554568
Returns **[Promise][66]\<void>** resolves when settled
555569

556570
### currentRouteName
@@ -1241,23 +1255,23 @@ Returns **([Array][70]\<Warning> | [Promise][66]<[Array][70]\<Warning>>)** An ar
12411255

12421256
[54]: #getdeprecations
12431257

1244-
[55]: #examples-22
1258+
[55]: #examples-23
12451259

12461260
[56]: #getdeprecationsduringcallback
12471261

12481262
[57]: #parameters-29
12491263

1250-
[58]: #examples-23
1264+
[58]: #examples-24
12511265

12521266
[59]: #getwarnings
12531267

1254-
[60]: #examples-24
1268+
[60]: #examples-25
12551269

12561270
[61]: #getwarningsduringcallback
12571271

12581272
[62]: #parameters-30
12591273

1260-
[63]: #examples-25
1274+
[63]: #examples-26
12611275

12621276
[64]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
12631277

addon-test-support/@ember/test-helpers/setup-application-context.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ export function setupRouterSettlednessTracking() {
130130
@param {string} url The URL to visit (e.g. `/posts`)
131131
@param {object} options app boot options
132132
@returns {Promise<void>} resolves when settled
133+
134+
@example
135+
<caption>
136+
Visiting the route for post 1.
137+
</caption>
138+
await visit('/posts/1');
139+
140+
@example
141+
<caption>
142+
Visiting the route for post 1 while also providing the `rootElement` app boot option.
143+
</caption>
144+
await visit('/', { rootElement: '#container' });
133145
*/
134146
export function visit(
135147
url: string,

0 commit comments

Comments
 (0)