vue-navigation
A page navigation library, record routes and cache pages, like native app navigation. 一个页面导航库,记录路由并缓存页面,像原生APP导航一样。
Top Related Projects
🚦 The official router for Vue 2
🚦 The official router for Vue.js
Quasar Framework - Build high-performance VueJS user interfaces in record time
The Intuitive Vue Framework.
📝 Minimalistic Vue-powered static site generator
Quick Overview
Vue-navigation is a lightweight Vue.js plugin that provides navigation management for single-page applications (SPAs). It offers a simple way to handle route transitions, manage navigation history, and implement back/forward functionality without relying on the browser's native history API.
Pros
- Easy integration with Vue.js projects
- Lightweight and performant
- Supports custom transition effects
- Provides a programmatic API for navigation control
Cons
- Limited documentation and examples
- May not be suitable for complex routing scenarios
- Lacks some advanced features found in more robust routing solutions
- Not actively maintained (last update was over 2 years ago)
Code Examples
- Basic usage:
import Vue from 'vue'
import Navigation from 'vue-navigation'
Vue.use(Navigation, {
router: router,
store: store
})
- Implementing a custom transition:
Vue.use(Navigation, {
router: router,
store: store,
transition: {
name: 'fade',
mode: 'out-in'
}
})
- Programmatic navigation:
this.$navigation.push('/new-page')
this.$navigation.back()
this.$navigation.forward()
Getting Started
- Install the package:
npm install vue-navigation
- Import and use the plugin in your main.js file:
import Vue from 'vue'
import router from './router'
import store from './store'
import Navigation from 'vue-navigation'
Vue.use(Navigation, { router, store })
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
- Use the navigation component in your App.vue:
<template>
<div id="app">
<navigation>
<router-view></router-view>
</navigation>
</div>
</template>
Competitor Comparisons
🚦 The official router for Vue 2
Pros of vue-router
- Official Vue.js routing solution with extensive documentation and community support
- Seamless integration with Vue.js core and ecosystem
- Advanced features like nested routes, navigation guards, and lazy loading
Cons of vue-router
- More complex setup and configuration for simple routing needs
- Larger bundle size due to additional features
Code Comparison
vue-router:
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const router = new VueRouter({
routes: [
{ path: '/foo', component: Foo },
{ path: '/bar', component: Bar }
]
})
vue-navigation:
import Vue from 'vue'
import Navigation from 'vue-navigation'
Vue.use(Navigation, {
router: router,
store: store
})
Key Differences
- vue-router is the official routing solution for Vue.js, while vue-navigation is a third-party plugin
- vue-navigation focuses on navigation management and state preservation, while vue-router provides comprehensive routing capabilities
- vue-router has a larger feature set and more active development, but vue-navigation offers a simpler API for basic navigation needs
Use Cases
- Choose vue-router for complex applications with advanced routing requirements
- Consider vue-navigation for simpler projects or when focusing on navigation state management
Community and Support
- vue-router has a larger community, more frequent updates, and extensive documentation
- vue-navigation has a smaller user base but can be suitable for specific navigation-focused scenarios
🚦 The official router for Vue.js
Pros of vue-router
- Official Vue.js routing solution with extensive documentation and community support
- Seamless integration with Vue.js core and ecosystem
- Advanced features like nested routes, navigation guards, and lazy loading
Cons of vue-router
- More complex setup and configuration for simple routing needs
- Larger bundle size due to additional features
Code Comparison
vue-router:
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
history: createWebHistory(),
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About }
]
})
vue-navigation:
import Navigation from 'vue-navigation'
Vue.use(Navigation, {
routes: [
{ path: '/', component: Home },
{ path: '/about', component: About }
]
})
Summary
vue-router is the official routing solution for Vue.js, offering robust features and seamless integration with the Vue ecosystem. It provides advanced capabilities but may be overkill for simple routing needs. vue-navigation, on the other hand, offers a more lightweight approach with simpler setup, making it suitable for basic navigation requirements. The choice between the two depends on the project's complexity and specific routing needs.
Quasar Framework - Build high-performance VueJS user interfaces in record time
Pros of Quasar
- Comprehensive UI framework with a large set of pre-built components
- Cross-platform development support (web, mobile, and desktop)
- Active community and regular updates
Cons of Quasar
- Steeper learning curve due to its extensive feature set
- Larger bundle size, which may impact initial load times
Code Comparison
vue-navigation:
import VueNavigation from 'vue-navigation'
Vue.use(VueNavigation, {
router,
store
})
Quasar:
import { Quasar } from 'quasar'
import '@quasar/extras/material-icons/material-icons.css'
import 'quasar/src/css/index.sass'
Vue.use(Quasar, {
config: {}
})
Summary
Quasar is a full-featured UI framework offering cross-platform development capabilities, while vue-navigation focuses specifically on navigation management in Vue.js applications. Quasar provides a wider range of components and tools but may require more time to learn and implement. vue-navigation is lighter and more focused, making it easier to integrate for simple navigation needs. The choice between the two depends on the project's scope and requirements.
The Intuitive Vue Framework.
Pros of Nuxt
- Full-featured framework with built-in routing, state management, and server-side rendering
- Large ecosystem and community support
- Automatic code splitting and optimized performance
Cons of Nuxt
- Steeper learning curve due to its comprehensive nature
- Potentially overkill for smaller projects
- More opinionated structure, which may limit flexibility in some cases
Code Comparison
vue-navigation:
import VueNavigation from 'vue-navigation'
Vue.use(VueNavigation, {
router,
store
})
Nuxt:
// nuxt.config.js
export default {
modules: [
'@nuxtjs/router'
],
router: {
// Router configuration
}
}
Key Differences
- vue-navigation is a lightweight plugin specifically for navigation management in Vue.js applications
- Nuxt is a comprehensive framework that includes navigation features along with many other capabilities
- vue-navigation requires manual setup and integration, while Nuxt provides a more integrated and opinionated approach
- Nuxt offers server-side rendering out of the box, which vue-navigation does not provide
Use Cases
- Choose vue-navigation for simple Vue.js projects that need basic navigation management
- Opt for Nuxt when building larger, more complex applications that benefit from its full-featured framework approach and server-side rendering capabilities
📝 Minimalistic Vue-powered static site generator
Pros of VuePress
- More comprehensive documentation solution, including static site generation
- Larger community and ecosystem, with more themes and plugins available
- Built-in markdown support and optimized for technical documentation
Cons of VuePress
- Heavier and more complex setup compared to vue-navigation
- May be overkill for simple navigation needs in Vue applications
- Steeper learning curve for developers new to static site generators
Code Comparison
VuePress configuration example:
module.exports = {
title: 'My Documentation',
themeConfig: {
nav: [
{ text: 'Home', link: '/' },
{ text: 'Guide', link: '/guide/' },
]
}
}
vue-navigation usage example:
import VueNavigation from 'vue-navigation'
Vue.use(VueNavigation, {
router,
store,
moduleName: 'navigation',
keyName: 'VNK'
})
Summary
VuePress is a more robust solution for creating documentation sites, offering a wide range of features and community support. However, it may be excessive for simple navigation needs. vue-navigation, on the other hand, is a lightweight plugin specifically designed for handling navigation in Vue applications, making it more suitable for projects that don't require full documentation capabilities.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
vue-navigation
require vue
2.x
and vue-router2.x
.
vue-navigation default behavior is similar to native mobile app (AãBãC are pages):
- A forward to B, then forward to C;
- C back to B, B will recover from cache;
- B forward to C again, C will rebuild, not recover from cache;
- C forward to A, A will build, now the route contains two A instance.
!important: vue-navigation adds a key to the url to distinguish the route. The default name of the key is VNK, which can be modified.
DEMO
Installing
npm i -S vue-navigation
or
yarn add vue-navigation
Usage
Basic Usage
main.js
import Vue from 'vue'
import router from './router' // vue-router instance
import Navigation from 'vue-navigation'
Vue.use(Navigation, {router})
// bootstrap your app...
App.vue
<template>
<navigation>
<router-view></router-view>
</navigation>
</template>
Use with vuex2
main.js
import Vue from 'vue'
import router from './router' // vue-router instance
import store from './store' // vuex store instance
import Navigation from 'vue-navigation'
Vue.use(Navigation, {router, store})
// bootstrap your app...
After passing in store
, vue-navigation
will register a module in store
(default module name is navigation
), and commit navigation/FORWARD
or navigation/BACK
or navigation/REFRESH
when the page jumps.
Options
Only router
is required.
Vue.use(Navigation, {router, store, moduleName: 'navigation', keyName: 'VNK'})
Events
functions: [ on
| once
| off
]
event types: [ forward
| back
| replace
| refresh
| reset
]
parameter( to
| from
) properties:
name
- type: string
- desc: name of the route(contains the key)
route
- type: object
- desc: vue-route`s route object
this.$navigation.on('forward', (to, from) => {})
this.$navigation.once('back', (to, from) => {})
this.$navigation.on('replace', (to, from) => {})
this.$navigation.off('refresh', (to, from) => {})
this.$navigation.on('reset', () => {})
Methods
Use Vue.navigation
in global environment or use this.$navigation
in vue instance.
getRoutes()
get the routing recordscleanRoutes()
clean the routing records
Top Related Projects
🚦 The official router for Vue 2
🚦 The official router for Vue.js
Quasar Framework - Build high-performance VueJS user interfaces in record time
The Intuitive Vue Framework.
📝 Minimalistic Vue-powered static site generator
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot