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: docs/faq/accessing-the-route.md
+4-10
Original file line number
Diff line number
Diff line change
@@ -58,8 +58,7 @@ It is still possible to access `useRoute()` or `this.$route` during that initial
58
58
59
59
Consider the following example. It tries to use the current route in `App.vue` to decide which layout to wrap around the `RouterView`:
60
60
61
-
```vue
62
-
<!-- App.vue -->
61
+
```vue [App.vue]
63
62
<script setup>
64
63
import DefaultLayout from './layouts/DefaultLayout.vue'
65
64
</script>
@@ -79,10 +78,7 @@ There are a few ways we might fix this problem.
79
78
80
79
Vue Router provides the method [`isReady()`](https://router.vuejs.org/api/interfaces/Router.html#isReady), which can be used to wait until it has resolved the route. We could use it to defer mounting the application until the route is ready:
81
80
82
-
```js
83
-
// main.js or main.ts
84
-
// ...
85
-
81
+
```js [main.js]
86
82
constapp=createApp(App)
87
83
88
84
app.use(router)
@@ -102,8 +98,7 @@ Depending on your application, that might not matter. A brief pause before the p
102
98
103
99
With a bit of extra effort, we could show a loading indicator if the route isn't resolved yet. There are a few ways we might implement this. One approach would be to use `router.isReady()` inside `App.vue` to track when the router is ready. e.g.:
104
100
105
-
```vue
106
-
<!-- App.vue -->
101
+
```vue [App.vue]
107
102
<script setup>
108
103
import { shallowRef } from 'vue'
109
104
import { useRouter } from 'vue-router'
@@ -128,8 +123,7 @@ Here we're using the `LoadingIndicator` component in place of the layout. The `L
128
123
129
124
We could also implement this using the slot of `RouterView`:
130
125
131
-
```vue
132
-
<!-- App.vue -->
126
+
```vue [App.vue]
133
127
<script setup>
134
128
import DefaultLayout from './layouts/DefaultLayout.vue'
135
129
import LoadingIndicator from './components/LoadingIndicator.vue'
Copy file name to clipboardexpand all lines: docs/faq/blank-page-in-production.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -121,7 +121,7 @@ Usually it's fairly obvious when this is happening, as the rest of the page rend
121
121
122
122
However, it can be tricky to tell whether routing is the problem if `App.vue` doesn't contain anything else. For example, imagine that `App.vue` just contains this:
123
123
124
-
```vue
124
+
```vue [App.vue]
125
125
<template>
126
126
<RouterView />
127
127
</template>
@@ -131,7 +131,7 @@ As `App.vue` only renders `<RouterView />`, we can't easily tell whether the pro
131
131
132
132
To help isolate the source of the problem, it is worth adding some extra temporary code to `App.vue`, to confirm that it is rendering correctly. For example:
Copy file name to clipboardexpand all lines: docs/faq/no-active-pinia.md
+12-20
Original file line number
Diff line number
Diff line change
@@ -189,15 +189,13 @@ The error is shown when step 3 occurs before step 2. The Pinia instance must be
189
189
190
190
But, in practice, it probably isn't that simple. In a real application, those 3 steps usually don't sit in the same file. More likely, they're in 3 separate files, something like this:
@@ -221,15 +219,13 @@ To understand that, we first need to understand `import`, and specifically how J
221
219
222
220
Let's start with a plain `.js` example. It works much the same way with `.ts` and we'll stick to `.js` throughout this page. It's a bit more complicated with `.vue` files, but we'll cover those later.
223
221
224
-
```js
225
-
// main.js
222
+
```js [main.js]
226
223
import { data } from'./store.js'
227
224
228
225
console.log('main.js', data)
229
226
```
230
227
231
-
```js
232
-
// store.js
228
+
```js [store.js]
233
229
constdata= { name:'Vue' }
234
230
235
231
console.log('store.js', data)
@@ -382,8 +378,7 @@ Generally speaking, you shouldn't be trying to access the store in top-level cod
0 commit comments