# think_router

> Middleware Router for ThinkKoa.

Latest version **2.0.2** (published 2020-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install think_router
pnpm add think_router
yarn add think_router
bun add think_router
```

## 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 | 2.0.2 |
| Published | 2020-02-28 |
| First published | 2017-06-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >8.0.0 |
| Dependencies | 2 |
| Unpacked size | 15.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | richenlin |
| Maintainers | richenlin |

## Links

- npm: https://www.npmjs.com/package/think_router
- Homepage: https://github.com/thinkkoa/think_router
- Issues: https://github.com/thinkkoa/think_router/issues
- npm.io page: https://npm.io/package/think_router

## Dependencies (2)

- [think_lib](https://npm.io/package/think_lib.md) ^2.x.x
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.1.0

## Recent versions

- 2.0.2 (latest) — 2020-02-28
- 2.0.1 — 2017-11-22
- 2.0.0 — 2017-11-16
- 1.2.0 — 2017-11-15
- 1.1.0 — 2017-10-31
- 1.0.12 — 2017-08-21
- 1.0.11 — 2017-08-18
- 1.0.10 — 2017-08-10
- 1.0.9 — 2017-07-14
- 1.0.8 — 2017-06-23
- 1.0.7 — 2017-06-23
- 1.0.6 — 2017-06-22
- 1.0.5 — 2017-06-19
- 1.0.4 — 2017-06-14
- 1.0.3 — 2017-06-14
- … 3 more at https://npm.io/package/think_router/versions

## README

# 介绍
-----

[![npm version](https://badge.fury.io/js/think_router.svg)](https://badge.fury.io/js/think_router)

Router for ThinkKoa.

# 安装
-----

```
npm i think_router
```

# 使用
-----

1、router中间件为thinkkoa内置中间件,无需在项目中创建引用。该中间件默认开启

2、项目中间件配置 config/middleware.js:
```
config: { //中间件配置
    ...,
    router: {
        multi_modules: false, //开启多模块支持
        deny_modules: ['common'], //禁止访问的模块(多模块模式)
        default_module: 'home', //默认的模块
        deny_controller: [], //禁止访问的控制器
        default_controller: 'index', //默认控制器
        default_action: 'index', //默认方法
        prefix: [], // url prefix
        suffix: ['.jhtml'], // url suffix
        subdomain_offset: 2,
        subdomain: {}, //subdomain
    }
}
```

### 自定义路由
除默认的单模块模式(controller/action)及多模块模式(module/controller/action）以外，还支持用户定制路由。
在项目中增加路由文件 config/router.js:
```
module.exports = {
    test: ['/product', {
        get: "/home/product/index"
    }],
    test1: ['/product/:id', {
        get: "/home/product/detail",
        post: "/home/product/add",
        put: "/home/product/update",
        delete: "/home/product/delete",
    }],
    test2: ['/product', "/home/product/index"]
}

```
按照实际项目需求进行修改即可。

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