Giter Site home page Giter Site logo

wx-vue-router's Introduction

vue-router-mp

npm bundle size npm downloads license

github travis

vue-router-mp 是在 mpvue 中使用的兼容 vue-router 的路由管理器,兼容常用大部分 vue-router 的 API。

支持的特性有:

  • 编程式的导航
  • 命名路由
  • 导航守卫
  • 路由元信息

请阅读 完整文档

安装

NPM

npm install vue-router-mp --save

直接下载

下载源码 并复制到你的工程。

小程序中引入

import Vue from 'vue'
import VueRouter from 'vue-router-mp'

// 或

const Vue = require('vue')
const VueRouter = require('vue-router-mp')

Vue.use(VueRouter)

起步

由于在小程序中,页面路径是由工程源码的目录结构决定,因此相比 vue-router,不需要再指定路径的组件。

// 1. 定义路由
// 此处由于小程序页面路径与源码一一对应,故无需配置组件
const routes = [
  { path: '/pages/foo' },
  {
    name: 'bar', // 命名路由
    path: '/pages/bar',
    isTab: true // 标记当前路由是一个 Tab
  }
]

// 2. 创建 router 实例,然后传 `routes` 配置
// 你还可以传别的配置参数, 不过先这么简单着吧。
const router = new VueRouter({
  routes // (缩写) 相当于 routes: routes
})

// 现在,应用已经启动了!

通过注入路由器,我们可以在任何组件内通过 this.$router 访问路由器,也可以通过 this.$route 访问当前路由:

export default {
  methods: {
    goBack () {
      window.history.length > 1
        ? this.$router.go(-1)
        : this.$router.push('/pages/foo')
    }
  }
}

请阅读 完整文档

wx-vue-router's People

Contributors

cweili avatar greenkeeper[bot] avatar dependabot-preview[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.