Git Product home page Git Product logo

cheers-mp-router's Introduction

cheers-mp-router

🚦精巧强大的小程序路由

催更、钉钉交流群:

钉钉交流群

使用

安装

npm i cheers-mp-router

typescript引入

import Router, { RouteConfig } from "cheers-mp-router";


// 定义路由配置
const routeConfigList: RouteConfig[] = [
  { name: "test-tabbar", path: "pages/tabbar/test-tabbar/index", isTab: true },
  { name: "testA", path: "test/pages/testA/index" },
  { name: "testB", path: "test/pages/testB/index" },
  { name: "product-details", path: "test/pages/product-details/index" }
];

// 实例化
const router = new Router({ routes: routeConfigList });

// 注册全局 beforeEach 钩子;使用方式和 vue-router 的 beforeEach 基本一致
router.beforeEach((to, from, next) => {
  console.log("当前路由", from);
  console.log("即将前往的路由", to);
  next();
  // next({ name: "pageB" });
  // next(false)
});

// 注册全局 afterEach 钩子
router.afterEach((current, from) => {
  console.log("跳转成功,当前路由:", current);
  console.log("之前路由:", from);
});

// 调用路由方法
router.push({ name: "testA" })

// 调用路由传参数
router.push({ name: "product-details", query: { id: "sb" } })

实例API

具体查看这里

TODO

  • cheers-mp 脚手架中使用时获得构建级别的路由支持、子包构建支持
  • push 支持 eventChannel 事件监听

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.