Skip to content

Commit 1a73ce0

Browse files
authored
feat: vapor mode (#2944)
* chore: upgrade Vue to 3.6.0-rc.16 * test: resolve Vue to its esm-bundler builds in vitest * refactor: share RouterView state * fix: allow guards and onRouteRendered in Vapor components * feat(experimental): add Vapor RouterLink and RouterView * feat(playground): toggle Vapor mode in the file-based playground * docs: add Vapor Mode guide * feat(playground): use vapor mode by default * docs: remove broken Vapor Mode link * feat: delete dead code when no options api is available * test: fix * refactor: simplify * test: remove redundant RouterLink tests and share the link router * chore: comments * test: fix * test: inline vue related deps * feat: do not register VDOM components in Vapor apps * feat: drop custom from the Vapor RouterLink * feat: deprecate custom in the experimental RouterLink * docs: no ssr support yet
1 parent 9608375 commit 1a73ce0

101 files changed

Lines changed: 2375 additions & 1085 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/docs/.vitepress/config/en.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ function sidebarFileBasedRouting(): SidebarGroup {
232232
text: 'Param Parsers (experimental)',
233233
link: '/experimental/param-parsers',
234234
},
235+
{
236+
text: 'Vapor Mode (experimental)',
237+
link: '/experimental/vapor',
238+
},
235239
],
236240
}
237241
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Vapor Mode
2+
3+
::: warning
4+
The Vapor components are experimental. They need Vue 3.6 or later. Their API can change in minor versions.
5+
:::
6+
7+
Vapor Mode apps need Vapor versions of `<RouterLink>` and `<RouterView>`. Import them from `vue-router/experimental/vapor`:
8+
9+
```ts
10+
import { RouterLink, RouterView } from 'vue-router/experimental/vapor'
11+
```
12+
13+
They have the same props, slots, and behavior as the [experimental `<RouterLink>`](./router-resolver) and the regular `<RouterView>`. They work with both `createRouter()` and `experimental_createRouter()`.
14+
15+
## Registering the components
16+
17+
Register the Vapor components yourself. In Vapor apps (`createVaporApp()` and `createVaporSSRApp()`), `createRouter()` does not register the VDOM components.
18+
19+
```ts{2,7,8,9}
20+
import { createVaporApp } from 'vue'
21+
import { RouterLink, RouterView } from 'vue-router/experimental/vapor'
22+
import App from './App.vue'
23+
import { router } from './router'
24+
25+
const app = createVaporApp(App)
26+
app.use(router)
27+
app.component('RouterLink', RouterLink)
28+
app.component('RouterView', RouterView)
29+
app.mount('#app')
30+
```
31+
32+
## Differences with the VDOM components
33+
34+
- Vapor Mode has no Options API: `$router` and `$route` are not available in templates, and `beforeRouteEnter`, `beforeRouteUpdate`, and `beforeRouteLeave` component options are not called. Use `useRouter()`, `useRoute()`, `onBeforeRouteUpdate()`, and `onBeforeRouteLeave()` instead.
35+
- In the `<RouterView>` slot, `Component` is the route component instance. Render it with `<component :is="Component" />`. Props and slots passed to `<component>` are ignored: [pass props from the route](../guide/essentials/passing-props) or use the attributes of `<RouterView>` instead. Template refs, `:key`, `<KeepAlive>`, and `<Transition>` work.
36+
- VDOM route components render through `vaporInteropPlugin`. Without it, every route component must be a Vapor component.
37+
- SSR hydration is not supported yet.

‎packages/docs/guide/advanced/navigation-guards.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ You can add the following options to route components:
287287
- `beforeRouteUpdate`
288288
- `beforeRouteLeave`
289289

290+
The router does not call these options if you set the [`__VUE_OPTIONS_API__` flag](https://vuejs.org/api/compile-time-flags.html) to `false`. Use the [Composition API guards](#Using-the-Composition-API) instead.
291+
290292
```vue
291293
<script>
292294
export default {

‎packages/docs/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"vitepress-plugin-group-icons": "^1.8.1",
2020
"vitepress-plugin-llms": "^1.14.0",
2121
"vitepress-translation-helper": "^0.2.2",
22-
"vue": "^3.5.45",
22+
"vue": "^3.6.0-rc.16",
2323
"vue-router": "workspace:*"
2424
}
2525
}

‎packages/experiments-playground/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type-check": "vue-tsc --build"
1111
},
1212
"dependencies": {
13-
"vue": "^3.5.45",
13+
"vue": "^3.6.0-rc.16",
1414
"vue-router": "workspace:*"
1515
},
1616
"devDependencies": {

‎packages/experiments-playground/vite.config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default defineConfig({
2424
__DEV__: 'true',
2525
__BROWSER__: 'true',
2626
__FEATURE_PROD_DEVTOOLS__: 'false',
27+
__FEATURE_OPTIONS_API__: 'true',
2728
__STRIP_DEVTOOLS__: 'false',
2829
},
2930
})

‎packages/playground-file-based/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
"dependencies": {
1313
"semver": "^7.8.6",
1414
"valibot": "^1.5.0",
15-
"vue": "^3.5.45",
15+
"vue": "^3.6.0-rc.16",
1616
"vue-router": "workspace:*",
1717
"zod": "^4.6.7"
1818
},
1919
"devDependencies": {
2020
"@types/semver": "^7.8.0",
2121
"@vitejs/plugin-vue": "^6.0.10",
22-
"@vue/compiler-sfc": "^3.5.45",
22+
"@vue/compiler-sfc": "^3.6.0-rc.16",
2323
"@vue/tsconfig": "^0.9.1",
2424
"auto-scaffold": "^1.0.1",
2525
"unplugin-auto-import": "^21.1.0",

‎packages/playground-file-based/src/App.vue‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<script setup lang="ts">
1+
<script setup lang="ts" vapor>
22
import { ref } from 'vue'
3-
import { useRouter } from 'vue-router'
3+
import { useRoute, useRouter } from 'vue-router'
44
55
const router = useRouter()
6+
const route = useRoute()
67
78
console.log(`We have ${router.getRoutes().length} routes.`)
89
@@ -42,8 +43,8 @@ const targetRoute = ref('')
4243
<div>
4344
<details>
4445
<summary>Route Info</summary>
45-
<p>Currently at "{{ $route.name }}" ({{ $route.fullPath }})</p>
46-
<pre>{{ $route.params }}</pre>
46+
<p>Currently at "{{ route.name }}" ({{ route.fullPath }})</p>
47+
<pre>{{ route.params }}</pre>
4748
</details>
4849
<form @submit.prevent="router.push(targetRoute)">
4950
<label>

‎packages/playground-file-based/src/components/SemVerInfo.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script lang="ts" setup>
1+
<script lang="ts" setup vapor>
22
import { computed } from 'vue'
33
import { inc, type SemVer } from 'semver'
44

‎packages/playground-file-based/src/main.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import { createApp } from 'vue'
1+
import { createVaporApp, vaporInteropPlugin } from 'vue'
22
import './style.css'
33
import App from './App.vue'
44
import { createPinia } from 'pinia'
55
import { PiniaColada } from '@pinia/colada'
66
import { router } from './router/resolver'
77
import { DataLoaderPlugin } from 'vue-router/experimental'
8-
import { RouterLink, RouterView } from 'vue-router'
8+
import {
9+
RouterLink as VaporRouterLink,
10+
RouterView as VaporRouterView,
11+
} from 'vue-router/experimental/vapor'
912

10-
const app = createApp(App)
13+
const app = createVaporApp(App)
14+
app.use(vaporInteropPlugin)
1115

1216
app.use(createPinia())
1317
app.use(PiniaColada, {})
1418
app.use(DataLoaderPlugin, {
15-
// FIXME: should be doable without `as any`
16-
router: router as any,
19+
router,
1720
})
18-
app.component('RouterLink', RouterLink)
19-
app.component('RouterView', RouterView)
21+
app.component('RouterLink', VaporRouterLink)
22+
app.component('RouterView', VaporRouterView)
2023
router.afterEach((to, from, failure) => {
2124
if (failure) {
2225
console.info('⛔️ Failed navigation', from.fullPath, '->', to.fullPath)

0 commit comments

Comments
 (0)