Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to disable browser backwards in react

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to prohibit browser fallback in react". The explanation in this article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to prohibit browser fallback in react".

First of all, think of monitoring mouse events, which include the following:

Click: click the event.

Dblclick: double-click the event.

Mousedown: triggered when the mouse button is pressed.

Mouseup: triggered when the pressed mouse button is released.

Mousemove: mouse movement event.

Mouseover (mouseenter): move into the event.

Mouseout (mouseleave): remove event.

Contextmenu: right-click event

None of the above events can monitor the back shortcut keys on the side of the mechanical keyboard and mouse.

Therefore, another method is adopted to prohibit the browser from going back.

ComponentDidMount () {

Window.addEventListener ('popstate', function () {

History.pushState (null, null, document.URL)

})

}

Note: the code will be added to the page where fallback is prohibited.

Jump from A to B as listed. If you prohibit page B from falling back to A. Then the above code is added to the A page.

Possible error report

Unexpected use of history no-restricted-global (disable specific global variables)

Solution: 'add widnow.' before history

ComponentDidMount () {

Window.addEventListener ('popstate', function () {

Window.history.pushState (null, null, document.URL)

})

}

In addition, do not delete the listening event in componentWillUnmount (), it will become invalid.

Thank you for reading, the above is the content of "how to prohibit browser fallback in react". After the study of this article, I believe you have a deeper understanding of how to prohibit browser fallback in react, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 203

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report