koa2-connect-history-api-fallback
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

README.md

koa2的一个中间件,用于处理vue-router使用history模式返回index.html,让koa2支持SPA应用程序。
我只是一个搬运工,让它兼容Koa2而已。详细说明请到原作者项目库查看
bripkens作者的connect-history-api-fallback

Install

$ npm install --save 'koa2-connect-history-api-fallback'

Use

在原作者的使用方法下增加了白名单选项,原作者的插件默认会将所有的请求都指向到index.html,这样可能就会导致项目内其他路由也被指向到index.html 使用方法如下:

const Koa = require('koa');
const { historyApiFallback } = require('koa2-connect-history-api-fallback');
// 或者当你使用 ES6 语法,你可以这样
import { historyApiFallback } from 'koa2-connect-history-api-fallback';
// 或者
import historyApiFallback from 'koa2-connect-history-api-fallback';
 
const app = new Koa();
 
// handle fallback for HTML5 history API
app.use(historyApiFallback({ whiteList: ['/api'] }));
 
// other middlewares
app.use(...);

Example

const Koa = require('koa');
 
// require 'koa2-connect-history-api-fallback' middleware
const { historyApiFallback } = require('koa2-connect-history-api-fallback');
 
// create app
const app = new Koa();
 
// use historyApiFallback
app.use(historyApiFallback());
 
// other middlewares
app.use(...);
 

LICENSE

Follow MIT License

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.3
    6,873
    • latest

Version History

Package Sidebar

Install

npm i koa2-connect-history-api-fallback

Weekly Downloads

6,898

Version

0.1.3

License

MIT

Unpacked Size

189 kB

Total Files

17

Last publish

Collaborators

  • shen7