@shene/wx-router
v0.1.5
Published
<!-- * @Author: shen * @Date: 2021-07-04 22:01:11 * @LastEditors: shen * @LastEditTime: 2021-07-30 10:33:23 * @Description: -->
Downloads
1
Readme
@shene/wx-router
安装
使用 npm:
$ npm install @shene/wx-router
使用 yarn:
$ yarn add @shene/wx-router
须知
- 需要开启 使用
npm
模块 - 需要开启 增强编译
- 安装后 需要构建 npm
开始使用
- 使用 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;
- 在页面中使用 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 () {},
})
);