简体   繁体   中英

How to prevent user from seeing login page after logged in?

I'm working on a react app, the issue is that after logging in and click on back button inside browser I can see the login page,

What should be the best approach to prevent this?

  1. Create a middleware in server side to protect this routes?
  2. Create a function that checks when the user clicks back/forward button?

Can you guide me a little bit??

If you are using react-router you can use redirect in your login component

if (userIsLogged) {
  return <Redirect to={"/homepage"} />;
} 

You can use Route Gurad Module

https://www.npmjs.com/package/react-router-guards or refer to this example as well.

How to restrict access to routes in react-router?

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