Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Filesystem Routing] Nested routes with sticky scrolling #1685

Open
brillout opened this issue Jun 11, 2024 · 5 comments
Open

[Filesystem Routing] Nested routes with sticky scrolling #1685

brillout opened this issue Jun 11, 2024 · 5 comments
Labels

Comments

@brillout
Copy link
Member

brillout commented Jun 11, 2024

Description

By default Vike scrolls the page to the top upon navigation.

The idea here is that the user would define /product/@id/%view (or /product/@id/@@view/) instead of /product/@id/@view to tell Vike that the page shouldn't scroll to the top.

Edit: Actually, a new setting scroll: false could be simpler.

@Blankeos In Next.js (and other frameworks) how does the user control whether the page scrolls to the top?

@Blankeos
Copy link

Blankeos commented Jun 11, 2024

@brillout Usually in other metaframeworks there's two ways to navigate:

  • Link (In the Markup)
  • Programmatically using a similar navigate API with Vike.

By default, the other metaframeworks work exactly like in regular HTML anchor tags wherein both approaches cause a scroll up to (0,0) scroll position. You can pass an optional prop/attribute to change that.

In NextJS:

In SvelteKIt:

@brillout
Copy link
Member Author

Do they also scroll to the top by default for nested layouts? I'm thinking of not scrolling nested route navigation by default.

@Blankeos
Copy link

Blankeos commented Jun 11, 2024

@brillout Just tested here, yup they do scroll to the top by default even for nested layouts.

Repro: https://github.com/Blankeos/nested-layouts-scroll-example

scroll-up-in-next-and-svelte.mp4

Also tested "no scroll" while I'm at it:

also-tested-no-scroll-while-im-at-it.mp4

@brillout
Copy link
Member Author

Actually, I don't know whether a nested route should induce a scroll-to-the-top or not. Some nested layouts require a scroll while others don't, and I'm not sure which is more frequent. I'd suggest we stick to always scrolling by default.

I think this ticket largely does the trick, with a much better DX than Next.js and SvelteKit.

As always, feel free to disagree.

@brillout
Copy link
Member Author

Actually, a new setting scroll: false could be a much simpler DX. I'll think more about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants