Answer the question
In order to leave comments, you need to log in
Why don't links work on heroku?
I uploaded a vue project to the Heroku server, but I noticed one feature - I can't just go to a link in my project. For example https://myapp.herokuapp.com/ here is the start page of my project, but if you go to https://myapp.herokuapp.com/app then heroku says that there is no such page "Cannot GET /app" although it is.
How can I make it so that I can get to any of the pages in the project by clicking on the link?
Thank you!
Answer the question
In order to leave comments, you need to log in
I found the answer
In the dist folder, if you know that for Heroku you need to make two files server.js and package.js
In package.js add this:
...
"scripts": {
"postinstall": "npm install express; npm install connect-history-api-fallback"
}
...
const express = require('express');
const path = require('path');
const history = require('connect-history-api-fallback');
const app = express();
const staticFileMiddleware = express.static(path.join(__dirname + '/'));
app.use(staticFileMiddleware);
app.use(history({
disableDotRule: true,
verbose: true
}));
app.use(staticFileMiddleware);
app.get('/', function (req, res) {
res.render(path.join(__dirname + 'index.html'));
});
var server = app.listen(process.env.PORT || 5000, function () {
var port = server.address().port;
console.log("App now running on port", port);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question