reactjs - 基于Ajax响应的Reactjs动态页面如何处理404?
问题描述
我用动态 ID 反应组件。
<Route path="/dashboard/tag/:id/" component={TagDetail}/>
<Route path="" component={NotFound}/>
在TagDetail
组件中,我基于返回数据调用服务器ID
,但是如果服务器返回ID
不存在于服务器(404 状态码),所以我想重定向到NotFound
组件。
在 TagDetail 组件中
fetch("URL", {'id": this.props.match.params.id})
.then(response => response.json()}
.then(data => {
this.setState({data})
})
它在ID
正确时起作用,因此服务器返回数据,但如果不是,则无法在其上显示 404 页面。
解决方案
推荐阅读
- image - 图像二进制解释:未知图像格式
- github - Gist 未在 Medium 中完全显示
- swift - Swift:几个 WKWebview 为同一个域 Cocoa 应用程序设置不同的 cookie
- python - 如何以数字方式在python中对字符串进行排序
- python - 过滤掉不相关的 cProfile 输出
- django - Django Ajax CSRF 验证失败
- physics - 创建戒指 ammo.js(三)
- android - Google Play Alpha:此帐户无法使用应用程序
- shell - ShellScript 在会话前命令 (PowerCenter) 上不起作用
- python - Sanic - 端点的路径类型不包括查询参数