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

has a popState #6498

Closed
maxguzenski opened this issue Sep 1, 2022 · 1 comment
Closed

has a popState #6498

maxguzenski opened this issue Sep 1, 2022 · 1 comment

Comments

@maxguzenski
Copy link

maxguzenski commented Sep 1, 2022

Describe the problem

I'm porting a react webapp to svelte, and I have a need to know when a page was loaded by push/replace or because the user pressed the browser's back button or if window.history.go(-1) method was called.

For this, I'm using my own code (below), but I would like to know if sveltekit could officially inform that.

Describe the proposed solution

This is working for my use case,
but I'm sure it doesn't work for all cases

import { browser } from '$app/environment'
import { afterNavigate } from '$app/navigation'

let idx = 0

export function listenPopState() {
	afterNavigate(() => {
		idx = window.history.state['sveltekit:index']
	})
}

export function isPopState() {
	return browser && idx > window.history.state['sveltekit:index']
}

Alternatives considered

No response

Importance

nice to have

Additional Information

No response

This was referenced Sep 1, 2022
@dummdidumm
Copy link
Member

Closed via #6537

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

Successfully merging a pull request may close this issue.

2 participants