How to use vuejs routing with history fallback and expressjs routes How to use vuejs routing with history fallback and expressjs routes express express

How to use vuejs routing with history fallback and expressjs routes


I was having the same issue. I fixed it by adding app.use(history()) after my api routes, but before app.use('/', express.static(path.join(__dirname, 'dist')));.

So I think for you it'd be like

const express = require('express');const path = require('path');const bodyParser = require('body-parser');const logger = require('morgan');const history = require('connect-history-api-fallback');const app = express();app.use(logger('dev'));app.use(bodyParser.json());app.get('/api', (req, res) => res.send('Hello World!'));app.use(history({  verbose: true}));app.use('/', express.static(path.join(__dirname, 'dist')));var port = process.env.PORT || 8080;app.listen(port);console.log('server started '+ port);

This answer helped me: https://forum.vuejs.org/t/how-to-handle-vue-routes-with-express-ones/23522/2