Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to get previous url in nextjs

//if user not logged in
if (!auth.user) {
  window.localStorage.setItem("path", router.asPath); //save current route
  router.replace("/login"); //send user to login page
  return <div> redirecting to login... </div>
}

//when user login
if (auth.user) {
  const path = localStorage.getItem("path")
  router.replace(path || "/"); //navigate to last route
  return <div> Loading... </div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript concat 
Javascript :: get string from textbox javascript 
Javascript :: how to remove duplicate values in array javascript 
Javascript :: javascript swap 
Javascript :: merge intervals 
Javascript :: Make Floating label TextInput in react native 
Javascript :: $$ promise then 
Javascript :: cet time zone right now 
Javascript :: express cookieparser 
Javascript :: Automatic Slideshow in react js 
Javascript :: an arrow function 
Javascript :: jquery get element by tag 
Javascript :: How to Return Specific Values from a Filter in Javascript 
Javascript :: convert json to excel in javascript 
Javascript :: Accessing user input through js 
Javascript :: sequelize inner join 
Javascript :: javascript this in settimeout 
Javascript :: javascript regex match sequence 
Javascript :: headless ui modal 
Javascript :: autocannon npm 
Javascript :: js add zeros before number 
Javascript :: Warning: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state. 
Javascript :: simple express server 
Javascript :: return object from map javascript 
Javascript :: flatlist inside flatlist react native 
Javascript :: javascript check if it has passed midnight 
Javascript :: How to pass json format data on ajax call 
Javascript :: for of and for in javascript 
Javascript :: javascript index of biggest number 
Javascript :: let a = {y;10}; 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =