Skip to content

Commit

Permalink
DOCS: API: add routing helper examples
Browse files Browse the repository at this point in the history
Let's add an example usage of all of the routing helpers (visit,
currentRouteName, currentURL) to the API docs.
  • Loading branch information
geneukum committed Oct 24, 2022
1 parent 325dee1 commit fa068a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
22 changes: 18 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,20 @@ Navigate the application to the provided URL.
* `url` **[string][64]** The URL to visit (e.g. `/posts`)
* `options` **[object][72]** app boot options

#### Examples

Visiting the route for post 1.

```javascript
await visit('/posts/1');
```

Visiting the route for post 1 while also providing the `rootElement` app boot option.

```javascript
await visit('/', { rootElement: '#container' });
```

Returns **[Promise][66]\<void>** resolves when settled

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

[54]: #getdeprecations

[55]: #examples-22
[55]: #examples-23

[56]: #getdeprecationsduringcallback

[57]: #parameters-29

[58]: #examples-23
[58]: #examples-24

[59]: #getwarnings

[60]: #examples-24
[60]: #examples-25

[61]: #getwarningsduringcallback

[62]: #parameters-30

[63]: #examples-25
[63]: #examples-26

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ export function setupRouterSettlednessTracking() {
@param {string} url The URL to visit (e.g. `/posts`)
@param {object} options app boot options
@returns {Promise<void>} resolves when settled
@example
<caption>
Visiting the route for post 1.
</caption>
await visit('/posts/1');
@example
<caption>
Visiting the route for post 1 while also providing the `rootElement` app boot option.
</caption>
await visit('/', { rootElement: '#container' });
*/
export function visit(
url: string,
Expand Down

0 comments on commit fa068a0

Please sign in to comment.