Socket
Socket
Sign inDemoInstall

vue-router

Package Overview
Dependencies
22
Maintainers
2
Versions
174
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue-router

> - This is the repository for Vue Router 4 (for Vue 3) > - For Vue Router 3 (for Vue 2) see [vuejs/vue-router](https://github.com/vuejs/vue-router).


Version published
Weekly downloads
2.9M
increased by1.99%
Maintainers
2
Install size
816 kB
Created
Weekly downloads
 

Package description

What is vue-router?

The vue-router npm package is the official router for Vue.js. It integrates closely with Vue.js core to make building Single Page Applications with Vue.js a breeze. Features include nested routes/mappings, modular, component-based router configuration, route params, query, wildcards, transitions, fine-grained navigation control, and view transition effects powered by Vue.js' transition system.

What are vue-router's main functionalities?

Dynamic Route Matching

This feature allows you to create routes that are dynamically matched to the path. For example, different user IDs can be matched to the same route pattern.

{"const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User }
  ]
})
const User = {
  template: '<div>User {{ $route.params.id }}</div>'
}"}

Nested Routes

This feature allows you to map nested paths to components. It's useful for creating sub-sections of a page without having to create complex configurations.

{"const router = new VueRouter({
  routes: [
    { path: '/user/:id', component: User,
      children: [
        {
          // UserProfile will be rendered inside User's <router-view>
          path: 'profile',
          component: UserProfile
        }
      ]
    }
  ]
})
const User = {
  template: '<div>User <router-view></router-view></div>'
}"}

Programmatic Navigation

Vue-router allows you to navigate without using <router-link> by using the router instance methods.

{"router.push('/home')
router.replace('/home')
router.go(-1)"}

Named Routes

Instead of using URLs, you can navigate using route names, making your code more readable and maintainable.

{"const router = new VueRouter({
  routes: [
    { name: 'user', path: '/user/:id', component: User }
  ]
})
// navigate to a named route
router.push({ name: 'user', params: { id: 123 }})"}

Route Guards

Route guards are used to protect routes that require authentication, perform checks before entering a route, or confirm navigation away from a route.

{"const router = new VueRouter({
  routes: [
    { path: '/secret', component: Secret, beforeEnter: (to, from, next) => {
      // ... guard logic
      next();
    }}
  ]
})"}

Other packages similar to vue-router

Readme

Source

vue-router release candidate test

  • This is the repository for Vue Router 4 (for Vue 3)
  • For Vue Router 3 (for Vue 2) see vuejs/vue-router.

Supporting Vue Router

Vue Router is part of the Vue Ecosystem and is an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:

Silver Sponsors

VueMastery Prefect

Bronze Sponsors

Stanislas Ormières Antony Konstantinidis Storyblok Nuxt UI Pro Templates


Get started with the documentation.

Quickstart

  • Via CDN: <script src="https://unpkg.com/vue-router@4"></script>

  • In-browser playground on CodeSandbox

  • Add it to an existing Vue Project:

    npm install vue-router@4
    

Changes from Vue Router 3

Please consult the Migration Guide.

Contributing

See Contributing Guide.

Special Thanks

BrowserStack Logo

Special thanks to BrowserStack for letting the maintainers use their service to debug browser specific issues.

FAQs

Last updated on 18 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc