unplugin-vue-router
Advanced tools
Changelog
0.9.0 (2024-05-28)
routes
import to avoid cyclic imports (63788f6), closes #132createRouter()
now requires the explicit router
property to be set and imported:import { createRouter, createWebHistory } from 'vue-router/auto'
+import { routes } from 'vue-router/auto-routes'
createRouter({
history: createWebHistory(),
+ routes
})
This also means that runtime extendRoutes()
option is not needed. It
has been deprecated and will be removed in the next major release.
Tree
and PrefixTree
insert method expects a path without the file
extension. They also expect the fullpath of the file as a second
argument (it used to be optional). This aligns better with their responsibility as they shouldn't be trimming the extension like they used to.// replace
tree.insert('file.vue')
// with
tree.insert('file', resolve('file.vue'))
This shouldn't affect most users as the Tree implementation is used internally to represent the folder structure.
"type": "module"
. It shouldn't
break anything for users but this is just in case, we all know how fragile this js ecosystem is sometimes...Changelog
0.8.4 (2024-02-24)
This patch contains the necessary fixes to allow importing the data loaders. However, they cannot be imported from vue-router/auto
nor from unplugin-vue-router/runtime
. Instead, they should be imported from unplugin-vue-router/data-loaders/...
. This is needed as some of the loaders depends on extra packages that not all users have installed. At the moment, there are two data loaders
unplugin-vue-router/data-loaders/basic
: https://uvr.esm.is/data-loaders/basic/unplugin-vue-router/data-loaders/pinia-colada
: https://uvr.esm.is/data-loaders/colada/Changelog
0.8.0 (2024-02-22)
Based on the feedback of the RFC, the Data Loaders have been redesigned from the ground up and are now way more flexible and powerful. As a result, if you were using the experimental data loaders, make sure to check the list of breaking changes and the new RFC at https://uvr.esm.is/rfcs/data-loaders. We are looking for early testers and feedback!
For people using the file-based routing, you now need to add unplugin-vue-router/client
to the types
property of your tsconfig. See setup for an example.
vue-router/auto-routes
(2dc0446)pending
to isLoading
(9502751)setupLoaderGuard
(8094f62)Remove the deprecated APIs:
createPrefixTree()
-> new PrefixTree()
VueRouterExports
-> VueRouterAutoImports
Data Loaders have been redesigned to be more flexible and account for other libraries. Notably, the caching behavior has been moved out of the basic loader to an extended one pinia-colada and the basic loader has no cache. All of the pending bugs have also been fixed. I recommend you to give the RFC examples a new read to get setup: https://uvr.esm.is/data-loaders/rfc. Most of the changes are simplifying things by removing them. Here is a list of the breaking changes to simplify migration:
dataFetching
option is no longer needed.HasDataLoaderMeta
has been
removed. It is just no longer needed. Loaders are picked up from lazy
loaded components and must otherwise be directly added to a meta.loaders
array. See the example at https://uvr.esm.is/data-loaders/rfc.html#basic-examplesetupDataFetchingGuard
has been replaced with a Vue
Plugin. See https://uvr.esm.is/data-loaders/rfc.html#data-loader-setup
for details.cacheTime
, use the staleTime
option in the
new defineColadaLoader()
based off @pinia/coladaunplugin-vue-router/data-loaders/...
. The good news is you
no longer need to use the plugin in order to benefit from the data
loaders; they can be imported even if you don't want file-based routing.If you find missing information or improvements, please open a Pull
Request to improve the CHANGELOG.md
.
Replace
import { setupLoaderGuard } from 'vue-router/auto'
setupLoaderGuard({ router, app })
with
import { DataLoaderPlugin } from 'vue-router/auto'
app.use(DataLoaderPlugin, { router })
vue-router/auto/routes
becomes vue-router/auto-routes
. This change was necessary to improve compatibility with
TypeScript and other tools in the ecosystem. Most of the time you don't
need to use this path but if you were using it, replace it:- import { } from 'vue-router/auto/routes'
+ import { } from 'vue-router/auto-routes'
Data Loaders now return an isLoading
property instead
of pending
. This aligns better with the wording of Data Loaders being
in a loading state rather than pending, which can have more meanings.
You know need to add unplugin-vue-router/client
to the types
property of your tsconfig. See setup for an example. This file contains the augmentation of the vue-router/auto
module that was previously in typed-router.d.ts
. You also need to set the modeResolution
to Bundler
in your tsconfig.json
.
the existing defineLoader
is being replaced by a
basic loader without cache. The version with cache will be implemented
by adding a library that properly handles the caching. This new strategy
will also enable other integrations like VueFire, Apollo, and custom
ones. Keep an eye (subscribe) to the RFC for news and to discus about
the future of Data Loaders: https://github.com/vuejs/rfcs/discussions/460
since data loaders aren't meant to be awaited in script setup (they are awaited at the navigation level), they now return a promise of the raw data only, not of the UseDataLoaderReturn, to make it clearer that this syntax is a bit special and should only be used within nested loaders. This change also brings other benefits like allowing lazy loaders to be awaited within loaders without changing their usage outside, in components. Also, allowing different types of commit while still allowing data to be awaited within loaders.