我使用react路由器v4。所以我试图(如果可能的话)在我的代码的头部返回一个状态代码404
export default class App extends Component {
displayName = App.name
render() {
return (
<Layout>
<Switch>
<Route exact path='/' component={Home} />
<Route path='/sitemap/:S' component={SiteMap} />
<Route path='/videos' component={Videos} />
<Route path='/contact' component={Contact} />
<Route path='/privacy' component={Privacy} />
{/*<Route path='/errorpage' component={Error404} status={404} />*/}
<Route component={Error404}/>
</Switch>
</Layout>
);
}
}发布于 2018-10-03 03:41:46
您可以很好地处理404Not Found页面,但不可能在客户端更新标头。
要更新头部,你必须将它设置为你的后端。例如,如果使用Express,则可以在代码的最后一层编写代码
app.use((error, req, res, next) => {
res.status(404).render('index');
//OR
res.status(404).sendFile('path/to/index.html') // Where index.html is your entry point
});https://stackoverflow.com/questions/52613811
复制相似问题