简体   繁体   English

如何跳过历史记录中的页面(使用react-router / js)

[英]How to skip over a page in history (with react-router/js)

Assume I have the following 3 paths: '/home' '/folder' '/folder/file'. 假设我有以下3条路径:'/ home''/ folder''/ folder / file'。

When the user visits '/folder/', it automatically redirects him to '/folder/file'. 当用户访问“ / folder /”时,它将自动将其重定向到“ / folder / file”。

However, this breaks the following flow: 但是,这中断了以下流程:

  1. visits /home 访问/首页
  2. visits /folder from /home, now the user is redirected to /folder/file 从/ home访问/ folder,现在将用户重定向到/ folder / file
  3. the user presses backspace. 用户按下退格键。

At this point, the user would get stuck in this infinite loop because the previous point in history is /folder which redirects him back to /folder/file. 此时,用户将陷入无限循环,因为历史记录中的上一个点是/ folder,它会将他重定向回/ folder / file。

My question is: How do I skip over '/folder' in history (when I hit backspace in /folder/file) and go directly to the last page in history that is not /folder. 我的问题是:如何跳过历史记录中的“ / folder”(当我在/ folder / file中单击退格键)并直接转到历史记录中不是/ folder的最后一页。

  1. if you are using history.pushState() to redirect, replace it with history.replaceState() 如果您正在使用history.pushState()进行重定向,则将其替换为history.replaceState()
  2. if you are using Redirect, https://github.com/rackt/react-router/blob/master/docs/API.md#redirect , this will not be a issue 如果您使用的是重定向, https://github.com/rackt/react-router/blob/master/docs/API.md#redirect ,这将不是问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM