美文网首页
BrowserRouter解决刷新"cannot GET /UR

BrowserRouter解决刷新"cannot GET /UR

作者: 账房先生2016 | 来源:发表于2019-04-30 16:31 被阅读0次
  1. 如果有服务器
import express from 'express';
const app = express();
import path from 'path';

app.use(express.static('dist'))

app.get('/*', (req, res) => {
    return res.sendFile(path.join( path.resolve(path.dirname('')), './dist', 'index.html'));
});

app.listen(3041, function () {
    console.log("Example app listening at port 3041")
});

index.html

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>TMRPlus-您的TMR车伴侣</title>
</head>

<body>
    <div id="root"></div>
    <!--导入 Webpack 输出的 JavaScript 文件-->
    <script src="/index.js"></script> // 路径非常重要。不能为./index.js或index.js
</body>

</html>
  1. 调试中解决该问题
// 在webpack config 中加入:
devServer: {
        historyApiFallback: true,
    },

相关文章

网友评论

      本文标题:BrowserRouter解决刷新"cannot GET /UR

      本文链接:https://www.haomeiwen.com/subject/ihpvnqtx.html