reactjs - how can fix refresh problem in react router
问题描述
i have a strange problem in my react application , i have two phase in my app , first is normal users that is web page and the other is dashboard for admins . in my dashboard when i refresh the page where ever i been the page redirects to /dashboard , for example i'm in /dashboard/cartable/requests then i refresh the page and page go to /dashboard page. my codes is in below : my app.js :
...
<Route exact path='/dashboard/' component={Index} />
<Route path='/dashboard/login' component={Index} />
<Route path='/dashboard/cartable' component={Index} />
<Route path='/dashboard/cartable/requests' component={Index} />
<Route path='/dashboard/cartable/approved' component={Index} />
<Route path='/dashboard/cartable/rejected' component={Index} />
<Route path='/dashboard/elections-management' component={Index} />
<Route path='/dashboard/statistics' component={Index} />
<Route path='/dashboard/statistics/assignee' component={Index} />
<Route path='/dashboard/statistics/participation' component={Index} />
<Route path='/dashboard/statistics/candidate-report' component={Index} />
<Route path='/dashboard/change-pass' component={Index} />
<Route path='/dashboard/errors' component={Index} />
...
in my index.js :
...
<Route exact path='/dashboard/' component={Layout} />
<Route exact path='/dashboard/cartable' component={Layout} />
<Route path='/dashboard/cartable/requests' component={Layout} />
<Route path='/dashboard/cartable/approved' component={Layout} />
<Route path='/dashboard/cartable/rejected' component={Layout} />
<Route path='/dashboard/elections-management' component={Layout} />
<Route exact path='/dashboard/statistics' component={Layout} />
<Route path='/dashboard/statistics/assignee' component={Layout} />
<Route path='/dashboard/statistics/participation' component={Layout} />
<Route path='/dashboard/statistics/candidate-report' component={Layout} />
<Route path='/dashboard/change-pass' component={Layout} />
<Route path='/dashboard/errors' component={Layout} />
...
in my layout.js :
...
<Route exact path='/dashboard' component={Requests} />
<Route exact path='/dashboard/cartable' component={Requests} />
<Route path='/dashboard/cartable/requests' component={Requests} />
<Route path='/dashboard/cartable/approved' component={Approved} />
<Route path='/dashboard/cartable/rejected' component={Rejected} />
<Route path='/dashboard/elections-management' component={ElectionManagement} />
<Route exact path='/dashboard/statistics' component={Participation} />
<Route path='/dashboard/statistics/assignee' component={Assignee} />
<Route path='/dashboard/statistics/participation' component={Participation} />
<Route path='/dashboard/statistics/candidate-report' component={CandidateReport} />
<Route path='/dashboard/change-pass' component={ChangePassword} />
<Route path='/dashboard/errors' component={Errors} />
...
解决方案
我相信如果您将“/dashboard”路线移到列表末尾,这可能会得到解决
推荐阅读
- angular - PrimeNg 手风琴给出 ExpressionChangedAfterItHasBeenCheckedError
- keycloak - 如何备份正在运行的 keycloak 实例?
- hadoop-yarn - Apache Impala - 类似 YARN 的查询 CPU 利用率报告(在 Cloudera 上)
- ios - 使用导航显示地图视图?.push(mapView) 并没有看到任何弹出
- authentication - 在 auth0 中,客户端 ID 是给定应用程序所独有的,还是设备上运行的应用程序的给定实例所独有的?
- python - 无法使用带有 Python 3.7 的套接字嗅探接口 eth2
- php - PHP通过ID从Mysql中获取行数据
- javascript - 循环遍历对象并显示图像
- java - executeQuery() 返回空的 ResultSet
- javascript - Redux 表单字段级别验证在 Edge 中不起作用