Skip to content

Instantly share code, notes, and snippets.

@deviationist
Created June 30, 2023 10:09
Show Gist options
  • Save deviationist/16921ea69a9685bd1b5eba50d2581319 to your computer and use it in GitHub Desktop.
Save deviationist/16921ea69a9685bd1b5eba50d2581319 to your computer and use it in GitHub Desktop.
A bare simple class made for Next.js with static methods to use as a shallow router (triggering changes in the URL without Next acting on them).
export class ShallowRouter {
static push(url: string): void {
window.history.pushState({ ...window.history.state, as: url, url }, '', url);
}
static replace(url: string): void {
window.history.replaceState({ ...window.history.state, as: url, url }, '', url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment