Keeping context provider state when navigating
Answered
Giant panda posted this in #help-forum
Giant pandaOP
I'm trying to build an audio player using Next.js, and one of the key features I want to support is that the user can keep listening to audio while browsing the app. I've implemented the audio player with a context provider. Whenever I navigate, the entire page seems to reload.
In SvelteKit, this is fairly straightforward, and only the parts of the page that actually changed reload (i.e., if I had the PlayerProvider sitting around the /app layout, and I navigated from /app/content/1 to /app/content/2, I wouldn't lose that context's state). Next.js's docs seem to imply the same should happen here, yet I lose the state on navigation.
Is what I'm trying to implement possible?
In SvelteKit, this is fairly straightforward, and only the parts of the page that actually changed reload (i.e., if I had the PlayerProvider sitting around the /app layout, and I navigated from /app/content/1 to /app/content/2, I wouldn't lose that context's state). Next.js's docs seem to imply the same should happen here, yet I lose the state on navigation.
Is what I'm trying to implement possible?
Answered by Giant panda
silly silly me forgot you're supposed to use
Link
from next/link
, not <a>
tags.4 Replies
Giant pandaOP
silly silly me forgot you're supposed to use
Link
from next/link
, not <a>
tags.Answer
u can also use useRouter for more control
Giant pandaOP
sweet, thanks!