Prevent Full Page Reload & Stop sidebar from scrolling to top
I am having an issue with my documentation. You can see more about the issue here: https://github.com/BayBreezy/ui-thing/issues/52
When I click a link from the navigation on the left, a full page reload is triggered. How do i prevent this?
The reload causes the navigation to scroll back to the top of the page.
You can visit this website to see what I am talking about : https://ui-thing.behonbaker.com/getting-started/introduction
GitHub
[Isuue] Documentation sidebar scroll jump to top when page change ·...
Hi . first of all thank you for your work its awsome . the issue is in Documentation when changing page sidebar will jump to top it would be good to stay on current page so when user explore compon...
UI Thing
UI Thing | TailwindCSS Component Library for Nuxt
UI Thing is a flexible and modern component library for Nuxt, offering reusable UI components styled with TailwindCSS and inspired by shadcn/ui. Simplify your development process with easy-to-integrate components and a powerful CLI tool.
2 Replies
Hi @baybreezy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the knowledge sources, I can offer some insights to address your issue with full page reloads and sidebar scrolling in your Nuxt application. However, please note that I cannot directly access or analyze external websites, so my response will be based solely on the provided knowledge sources and the general description of your problem.
To prevent full page reloads and stop the sidebar from scrolling to the top when clicking links in your navigation, you can consider the following approaches:
1. Use
<NuxtLink>
instead of regular <a>
tags:
Make sure you're using <NuxtLink>
components for internal navigation instead of regular <a>
tags. <NuxtLink>
is designed to handle client-side navigation without triggering full page reloads.
2. Check for custom attributes on router links:
If you're using custom attributes or slot templates with your router links, ensure they're implemented correctly. As mentioned in the Stack Overflow post about Vue Router (https://stackoverflow.com/questions/77282478), you might need to add a click handler to your <a>
tags within router links:
3. Implement keep-alive for pages:
To prevent remounting of pages when navigating, you can use the keepalive
property. As mentioned in a GitHub issue comment (https://github.com/nuxt/nuxt/issues/30221), you can set this globally in your nuxt.config.js
:
You can then opt out of keep-alive for specific pages if needed:
4. Adjust scroll behavior:
To prevent the sidebar from scrolling to the top, you might need to customize the scroll behavior. A recent fix in Nuxt addresses scroll issues, as mentioned in this GitHub pull request (https://github.com/nuxt/nuxt/pull/25817). Ensure you're using the latest version of Nuxt, which should include this fix.
5. Use the Aside component:
If you're using Nuxt UI Pro, consider using the Aside component (https://ui.nuxt.com/pro/getting-started#aside) for your sidebar, which is designed to be sticky:
6. Check for SSR mode:
Ensure that you haven't disabled SSR mode in your nuxt.config.ts
, as this can affect navigation behavior:
If these suggestions don't fully resolve your issue, you might need to investigate further or consider opening an issue on the Nuxt GitHub repository with a minimal reproduction of your specific problem.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@882659428795568138> Kapa.ai is still learning and improving, please let me know how I did by reacting below.