wepy-router

1.1.6 • Public • Published

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)
  }
}

License

ISC

Readme

Keywords

Package Sidebar

Install

npm i wepy-router

Weekly Downloads

3

Version

1.1.6

License

ISC

Unpacked Size

23.5 kB

Total Files

5

Last publish

Collaborators

  • mackkkk