我的反應路由器工作正常與開發ENV,這就是我的WebPack開發服務器那樣:重新加載時無法獲得錯誤404?
historyApiFallback: {
index: 'index.html',
}
所以在生產模式,我想這樣做,我做到了,在快遞這樣的:
const indexPath = path.join(__dirname, '../public/index.html')
const publicPath = express.static(path.join(__dirname, '../public'))
app.use('/public', publicPath)
app.use('/graphql', graphQLHTTP(async (req) => {
let { user } = await getUser(req.headers.authorization);
if(!user) {
user = 'guest'
}
return {
schema,
pretty: true,
graphiql: true,
context: {
user,
}
}
}));
app.get('/', function (_, res) { res.sendFile(indexPath) });
我沒有改變任何東西與react-router-dom所以我假設錯誤是在我的明確配置。那麼在生產模式下,historyApiFallback有什麼作用?下面是我的WebPack捆綁配置:
output: {
path: path.join(__dirname, 'public'),
filename: 'bundle.js',
publicPath: '/public/'
},
在我的HTML
我引用束這樣的:
<script type="text/javascript" src="/public/bundle.js"></script>
我覺得有合適的配置,但是當我重裝,我得到無法得到錯誤404?
這有效,'/'如何使用'*'而'/'沒有使用? –
我更新了我的答案!如果您覺得此答案可以解決問題,請點擊綠色的選中標記將其標記爲「已接受」。 – imcvampire