尽管进行了设置,但刷新的vue应用在开发和生产中仍会出现“无法获取/ route”错误

时间:2019-11-18 09:51:10

标签: javascript vue.js vue-router page-refresh

我正在使用vue 2.6.10和节点v10.16.0并表示4.17.1。

在我的var token = this.adalSvc.acquireToken('https://api.partnercenter.microsoft.com').subscribe((token: string) => { console.log("test"); console.log(token); localStorage.setItem('AuthContextToken', JSON.stringify(token)); }); 中,

vue.config.js

const path = require('path'); module.exports = { outputDir : path.resolve(__dirname, 'dist'), devServer:{ proxy:{ '/*':{ target:'http://localhost:4000' } } } } 上,我有

router.js

在我的const router = new Router({ mode: "history", base: process.env.BASE_URL, routes: [ //........ 节点中,根据我在线上看到的内容,

app.js

如果执行此操作,则刷新会在开发过程中出现var history = require('connect-history-api-fallback'); const staticFileMiddleware = express.static(path.join(__dirname,'quad-client')); const app = express(); app.use(staticFileMiddleware); app.use(history({ disableDotRule: true, verbose: true })); app.use(staticFileMiddleware); app.use(cors()); app.use(express.static(path.join(__dirname,'public'))); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:false})); app.use(express.json()); app.use(express.urlencoded({extended:false})); app.use('/vesselperformance', require('./routes/vesselperformance')); //more routes const port = process.env.PORT || 4000; app.listen(port, ()=>{ console.log('server runs on port ', port); }); 错误,而在生产环境中,当我转到Cannot GET /route时将看不到该应用程序

我必须像这样编辑节点localhost:4000(删除与app.js相关的代码)

connect-history-api-fallback

这将在const app = express(); app.use(cors()); app.use(express.static(path.join(__dirname,'public'))); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended:false})); app.use(express.json()); app.use(express.urlencoded({extended:false})); app.use('/login', require('./routes/login')); //more routes if(process.env.NODE_ENV === 'production'){ //static folder app.use(express.static(path.join(__dirname,'public'))); //handle SPA app.get(/.*/, (req, res)=>{ res.sendFile(__dirname + '/public/index.html'); }); } const port = process.env.PORT || 4000; app.listen(port, ()=>{ console.log('server runs on port ', port); }); 中显示该应用,但是在刷新生产和开发方面仍然存在相同的问题。

我想念什么?如何解决刷新问题?谢谢。

0 个答案:

没有答案