Klark
Klark

Reputation: 483

Koa2 and History API fallback

I build SPA app, and I setup history mode in my router on frontend. I use Vue2.js - here is problem describe only server configuration for Express.js, but I didn't know how to setup proper server configuration for my Koa2 app.

I take connect-history-api-fallback middleware:

app.use(history());

but I got error:

TypeError: next is not a function

Then I use koa2-history-api-fallback module but didnt't work eather.

Is there any workaround, or any way to handle this problem.

Thanks a lot.

Upvotes: 0

Views: 881

Answers (1)

Sebastian Hildebrandt
Sebastian Hildebrandt

Reputation: 2781

koa2-history-api-fallback is an adapter for connect-history-api-fallback for Koa ^2.0.0. So basically using koa2-history-api-fallback should be the correct way.

This code should work:

const Koa = require('koa')
const app = new Koa();
const historyFallback = require('koa2-history-api-fallback')

app.use(historyFallback({
  index: '/index.html'
}))

app.listen(3000);

If you have any problems with this, can you provide your error messages?

Upvotes: 1

Related Questions