Coder Social home page Coder Social logo

cyonet / koa2-connect-history-api-fallback Goto Github PK

View Code? Open in Web Editor NEW

This project forked from idseventeen/koa2-connect-history-api-fallback

0.0 1.0 0.0 6 KB

Fallback to index.html for applications that are using the HTML 5 history API

License: MIT License

JavaScript 100.00%

koa2-connect-history-api-fallback's Introduction

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');
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(...);

koa2-connect-history-api-fallback's People

Contributors

idseventeen avatar

Watchers

 avatar

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.