简体   繁体   中英

Back and forward button event handling

So I'm making a single page app with only one URL (/main) and no routing. How can I track forward and back button click in browser so I can do the logic to navigate between rendering different components? Is it even possible?

Yes, you can implement this easily and approximately. Put 2 buttons (Next, Previous) and use useState hook. Then by clicking Next , increment the state and by Previous button, decrement the state. Then in JSX you can check it out and render the components you want.

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