taro的微信小程序路由
taro
$ npm install taro-router-wx
// React
import React, { Component } from 'react'
import router from 'taro-router-wx'
router.installReact(React)
// Nerv
import Taro, { Component } from "@tarojs/taro";
import router from 'taro-router-wx'
router.installNerv(Taro)
// Vue
import Vue from 'vue'
import router from 'taro-router-wx'
Vue.use(router)
//
router.beforeEach((to, from, next) => {
console.log(':', to.path)
console.log(':', from.path)
// todo ..
// nextresolve
next()
//
next(false)
//
next({path:'pages/test/index', query:{ test: 1 }})
})
//
router.afterEach((res, page) => {
console.log(' ===========')
console.log('', res)
console.log('', res.openType)
console.log('', res.path)
console.log('', res.query)
console.log('webviewId', res.webviewId)
console.log('', res.scene)
console.log('', page)
// todo ..
})
// class
// ReactVue this.$router
// Nerv this.$$router
let location = {path: 'pages/test/index', query:{ test:1 }}
//
// let location = 'pages/test/index?test=1'
// navigateTo
this.$router.push(location)
// redirectTo
this.$router.replace(location)
// switchTab
this.$router.switchTab(location)
// relaunch
this.$router.relaunch(location)
// navigateBack
this.$router.back()
//
this.$router.getPageOpenTypeSync(openType =>
console.log('', openType)
)
//
this.$router.query
//
this.$router.path
//
this.$router.fullPath
//
this.$router.currentPage
//
this.$router.history.length
//
import { useRouter } from 'taro-router-wx'
const router = useRouter()
// navigateTo
router.push(location)
// apiclass