简体   繁体   中英

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

Assume I have the following 3 paths: '/home' '/folder' '/folder/file'.

When the user visits '/folder/', it automatically redirects him to '/folder/file'.

However, this breaks the following flow:

  1. visits /home
  2. visits /folder from /home, now the user is redirected to /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.

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.

  1. if you are using history.pushState() to redirect, replace it with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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