James Clare
James Clare

Reputation: 563

vue-router and Express

I've build a simple app using Vue.js and their vue-cli webpack.

I've used vue-router to control navigation around the site with the different views. This works fine when running locally.

I'm now wanting to deploy this onto Heroku, however the urls are no longer working. I've tried implementing middlewares, but have hit a brick wall!

I'm looking for something that might lead me along the right lines to configure node.js/express to run the app correctly.

Many thanks,

James

Upvotes: 17

Views: 12106

Answers (1)

James Clare
James Clare

Reputation: 563

For those in a similar situation, now working using:

const express = require('express');
const history = require('connect-history-api-fallback');
const app = express();

const staticFileMiddleware = express.static(__dirname);
app.use(staticFileMiddleware);
app.use(history({
  disableDotRule: true,
  verbose: true
}));
app.use(staticFileMiddleware);

const port = 5555;
app.listen(port, () => {
  console.log(`Example app listening on port ${port}!`);
});

You can learn more about connect-history-api-fallback

Upvotes: 33

Related Questions