Skip to content

Support for Shallow Routing (from Next.js) #2673

@ghost

Description

Describe the problem

See: https://nextjs.org/docs/routing/shallow-routing

Shallow routing allows you to change the URL without running data fetching methods again, (...) [it] only works for same page URL changes.

Describe the proposed solution

import { goto } from '$app/navigation';
await goto(href, { shallow: true });

plus

<a sveltekit:shallow {href}></a>

These would update the page store, but load would not run. (Only if href does not link to a new page)

Alternatives considered

Using the History API directly:

history.replaceState(history.state, document.title, href)

But doing this does not update the page store (and it's ugly).

Importance

would make my life easier

Additional Information

I have this OrgTree component which lazy loads it's items as you expand the groups:

20211023151814

When you click an item the URI is updated using shallow routing, leaving all the loaded tree data intact.

Using Svelte Kit, load fetches the initial tree data, but, after navigating, the initial data is loaded again, reseting the whole tree.

Related issues: #1930, #969

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions