Next.js Discord

Discord Forum

How Can I Update State To The Correct Value Depending On Which Page A User Enters Through/Reloads To

Answered
Eurasian Collared-Dove posted this in #help-forum
Open in Discord
Eurasian Collared-DoveOP
Hey, I have a navbar I'm working on currently and the buttons have state to highlight them when they are clicked, adding the highlight on click is pretty simple by using a state defined by an enum page either HOME = "home" or LOGIN="login" etc, however when the page is reloaded the state does not persist as well as when loading into the application through a route like localhost:3000/login has the default home nav tab selected. Is there any way to read the URL in my layout page and set a state variable based upon which page a user is on? I can provide code if my description is lackluster. Any and all help is very greatly appreciated! Thank you!

3 Replies