Skip to content

Commit 2a2cf42

Browse files
Add 'Using location instead' to accessing-the-route.md (#44)
1 parent b21b2de commit 2a2cf42

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/faq/accessing-the-route.md

+14
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,17 @@ import LoadingIndicator from './components/LoadingIndicator.vue'
146146
```
147147

148148
The trick here is that the `Component` in the slot props will be `undefined` if the route hasn't resolved yet.
149+
150+
## Using `location` instead
151+
152+
The examples above used `meta`, which is tied to the route. But sometimes we might not need the route itself, we only need information that is present in the URL. Rather than waiting for Vue Router to resolve the route, we could parse the URL ourselves.
153+
154+
Let's imagine we have a URL like `http://example.com/users?page=1`. We could parse that using something like this:
155+
156+
```js
157+
const path = location.pathname // '/users'
158+
const search = location.search // '?page=1'
159+
const page = new URLSearchParams(search).get('page') // '1'
160+
```
161+
162+
Reference: <https://developer.mozilla.org/en-US/docs/Web/API/Location>

0 commit comments

Comments
 (0)