This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Shadab Ali
Hi Guys
Back with another real-life scenario in software development.
Do you know when you are scrolling to some famous websites like LinkedIn, Facebook, etc without logging in?
And when you want to comment or like a post but that requires a login and After login, the website will take you to the same post or Article
How did this happen?
It is actually very easy to do,
just append the URL of the post as a query parameter in the login URL.
const goToLoginPage=()=>{
/login?redirectTo=${router.asPath}
router.push();
}
And in the login API function just checks if the URL contains this param and then send the user to this route
async function loginUser(){
const { redirectTo } = router.query;
const res=await loginApi(); ;
if(res.success){
router.push(redirectTo ?? '/');
}
}
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Shadab Ali
Shadab Ali | Sciencx (2022-09-25T14:05:59+00:00) After Login redirect Back to post where you are reading without login. Retrieved from https://www.scien.cx/2022/09/25/after-login-redirect-back-to-post-where-you-are-reading-without-login/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.