Skip to content

v4.0.0

Compare
Choose a tag to compare
@github-actions github-actions released this 07 Dec 10:20

Vue logo

A more complete but lighter Router

Today Vue Router 4 is officially released as stable.
After 14 alphas, 13 betas and 6 release candidates, Vue Router v4 is ready to bring the best of routing to your Vue 3 applications with improved bundle size, TypeScript integration, new features and consistency improvements for modern apps.

It has taken almost 2 years of work, around 1500 commits, 15 RFCs, and the help of many users and their bug reports and feature requests to get here. Thank you all for your very much appreciated help!

Project Organization improvements

Vue Router is now divided in three modules:

  • History implementation: handles the address bar and is specific to the environment Vue Router runs on (Node, Browser, Mobile, etc)
  • Router Matcher: handles the parsing of routes /users/:id and its ranking
  • Router: connects everything together and handle routing specific features like navigation guards

Dynamic Routing

One the most wanted features on Vue Router is Dynamic Routing. It makes the router more flexible and powerful and open possibilities for applications that were not possible before! This is possible thanks to an advanced path parsing with automatic ranking, allowing the router to guess what route should be matched based on the URL string representation, allowing user to define routes in any order.

Improved Navigation system

The new navigation system is more consistent and improves the experience of Scroll Behavior to match native browser behavior. It also gives users almost more information about the status of a navigation and allow using that information to improve user experience through global UI elements like progress bars and modals.

More powerful Devtools

Thanks to the new Vue Devtools, Vue Router is able to create more advanced integrations: navigation in the timeline and a complete route directory that helps you debug routes.

Better Navigation guards

Say good bye to next and avoid easy-to-make mistakes inside navigation guards: return any value you were passing to next. The previous version is still supported to ease migration!

More information on the updated documentation.

Consistent encoding in routes

Encoding has been adapted to make it consistent across different browsers and route location properties (params, query and hash). You don't need to encode these properties when passing them to router.push() and they will always appear decoded in the route locations (e.g. $route and useRoute()).

Small migration path

Vue Router 4 focus on improving the existing Router while keeping a very similar API, migration should be short and almost limited to a few renames if you were using the basics of Vue Router. You can check the full migration guide on the documentation

The future of the Router

Vue Router has been effectively stable for the past couple of months and makes it possible to now focus on:

  • Better Developer experience with existing tooling (Vetur, Vite, Devtools, etc)
  • Better integration with modern features like Suspense
  • RFCs to improve the existing API or bring new ones
  • Lighter versions of the router

Trying It Out

If you want to give Vue Router 4 a quick try, you can check this CodeSandbox, this Vite template with Tailwind CSS, or use the CLI to get started.

To Learn more about Vue Router 4, check out our new documentation. If you are an existing Vue 2.x user, go directly to the Migration Guide.

Supporting Vue Router Development

If your company uses Vue Router, please consider supporting its development by supporting me 🙏 . It will mean a lot and really help me to keep working on improving the Vue Ecosystem.


If you were already using the release candidate version of vue router, you can find the list of improvements on the CHANGELOG.md.