# uni-router-mini

> Routing tool for uniapp

Latest version **1.1.5** (published 2023-08-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install uni-router-mini
pnpm add uni-router-mini
yarn add uni-router-mini
bun add uni-router-mini
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2023-08-17 |
| First published | 2020-02-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Jerison Paul |
| Maintainers | jerison-paul |
| Keywords | uniapp, uni-app, vue, router, vue-router |

## Links

- npm: https://www.npmjs.com/package/uni-router-mini
- Repository: https://github.com/JerisonPaul/uni-router-mini
- Issues: https://github.com/JerisonPaul/uni-router-mini/issues
- npm.io page: https://npm.io/package/uni-router-mini

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.1.5 (latest) — 2023-08-17
- 1.1.4 — 2020-03-26
- 1.1.3 — 2020-02-14
- 1.1.2 — 2020-02-12
- 1.1.1 — 2020-02-12
- 1.1.0 — 2020-02-12
- 1.0.0 — 2020-02-11

## README

# uni-router-mini
> 简易版 [Vue-router](https://router.vuejs.org/zh/) 专门为 [uni-app](https://uniapp.dcloud.io/) 服务

## 介绍

uni-router-mini 专为 uni-app 设计,  主要解决 uni-app 没有路由拦截问题。

## 使用
___routes.js需要与pages.json配置的路径一致___
* router/routes.js 

    ```
     /**
       * @description param intro
       * @param path       必须填充需要与pages.json的路径一致.
       * @param name       不必填，这取决于您的需求.
       * @param meta       可以放入您需要的参数，如“requireAuth”，用作是否拦截的条件
       */
       
     const routes = [
        {
          path: '/pages/index/index',  // 必填   
          name: 'index',
          meta: {
            title: 'index',
            requireAuth: false
          }
        }
     ]
      
      export default routes  
    ```
* main.js 
    ```
      /**
      * @description router
      * beforeEach 
      *      to: 目标路有对象
      *      next: 是否执行下一步的调用函数，类似vue-router
      */
      
      import _routes from './router/routes'
      import Router from 'uni-router-mini'
      
      // registration routing
      const router = new Router({
        routes: _routes
      })
      
      // Front navigation
      router.beforeEach((to, next) => {
        if (to.meta.requireAuth == undefined || to.meta.requireAuth) {
            next()
        } else {
            next()
        }
      })
      
      Vue.prototype.$router = router
    ```    
   
* 页面使用

   ```
      this.$router.push({ path : '', query: { a:1 } }) 等价于 uni.navigateTo()
      
      this.$router.redirectTo({ path : '', query: { a:1 } }) 等价于 uni.redirectTo()
      
      this.$router.switchTab({ path : '', query: { a:1 } }) 等价于 uni.switchTab()
      
      this.$router.reLaunch({ path : '', query: { a:1 } }) 等价于 uni.reLaunch()
      
      this.$router.back({ path : '', query: { a:1 } }) 等价于 uni.navigateBack()
      
    ```
   * Receiving parameters
   
  ```
    onLoad(options) {
        const query = options.query
        const a = query.a         
    }
     
  ```

---
_Source: https://npm.io/package/uni-router-mini · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
