wepy-router
v1.1.6
Published
use wx router api like vue-router
Downloads
5
Readme
Wepy-router
Install
npm i wepy-router --save
Config & Init
app.wepy
import Router from 'wepy-router'
const config = {
pages: ['pages/index'],
subPackages: [
{
root: 'pages/common',
pages: ['a', 'b']
},
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'xxx',
navigationBarTextStyle: 'black'
}
}
export default class extends wepy.app {
config = config;
router = new Router(config);
globalData = {};
constructor() {
super()
this.use('requestfix')
}
onLaunch() {
console.log(wepy.$router)
}
}
Useing in page or component
[default navigate]
wepy.$router.push('/pages/common/a', {
id: 1
})
or
wepy.$router.push({
path: '/pages/common/a',
query: {
id: 1
}
})
use by name
wepy.$router.push({
name: 'CommonA'
})
[reLaunch]
wepy.$router.push({
path: '/pages/common/b',
relaunch: true
})
or
wepy.$router.push(path: '/pages/common/a',{},true)
[navigate back or front]
Back to last page
wepy.$router.go(-1)
Going front
wepy.$router.go(1)
You won't be caring about if it should be switching tabbar
More than pages length have disposed
More
if you want to use this insdead of wepy.$router
import { routerMinx } from 'wepy-router'
export default class Index extends wepy.page {
mixins = [routerMinx]
onLoad() {
conosle.log(this.$router)
}
}
or
import {withRouter} from 'wepy-router'
@withRouter
export default class Index extends wepy.page {
onLoad() {
conosle.log(this.$router)
}
}