0.1.5 • Published 3 years ago

@shene/wx-router v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

@shene/wx-router

安装

使用 npm:

$ npm install @shene/wx-router

使用 yarn:

$ yarn add @shene/wx-router

须知

  1. 需要开启 使用npm模块
  2. 需要开启 增强编译
  3. 安装后 需要构建 npm

开始使用

  1. 使用 createRouter 创建 router 对象
// /router/index.js
import createRouter from '@shene/wx-router';
const whites = ['/pages/home/index'];

const router = createRouter({
  whites,
});

router.beforeEach((to, next) => {
  console.log(to, next);
  next('/pages/login/index');
});

router.beforeLoad((currentPath, next) => {
  if (whites.includes(currentPath)) {
    return true;
  }
  next('/pages/login/index');
  return false;
});

export default router;
  1. 在页面中使用 router
// /pages/home/index.js
import { withRouter } from '@shene/wx-router';
import router from '../router/index';

Page(
  withRouter(router, {
    auth: false, //配置auth=false的话不在走beforeLoad拦截
    data: {
      name: '2222',
    },
    onReady: function () {},
    onShow: function () {},
    onHide: function () {},
    onUnload: function () {},
    onPullDownRefresh: function () {},
    onReachBottom: function () {},
    onShareAppMessage: function () {},
  })
);

License

MIT

0.1.5

3 years ago

0.1.2

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago