Store previous page globally from beforeNavigate

This commit is contained in:
2022-06-13 14:21:23 +02:00
parent 9a63338c92
commit 622e304efa
2 changed files with 4 additions and 5 deletions

View File

@@ -66,7 +66,7 @@
} }
// Define previous URL // Define previous URL
$: previousUrl = $previousPage ? $previousPage : `/${location.country.slug}/${location.slug}` $: previousUrl = $previousPage ?? `/${location.country.slug}/${location.slug}`
/** /**

View File

@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import '../style/style.scss' import '../style/style.scss'
import { navigating, page } from '$app/stores' import { navigating, page } from '$app/stores'
import { beforeNavigate } from '$app/navigation'
import { onMount, setContext } from 'svelte' import { onMount, setContext } from 'svelte'
import { pageLoading, previousPage } from '$utils/stores' import { pageLoading, previousPage } from '$utils/stores'
import { DURATION } from '$utils/contants' import { DURATION } from '$utils/contants'
@@ -24,10 +25,8 @@
* On page change * On page change
*/ */
// Store previous page (for photo Viewer close button) // Store previous page (for photo Viewer close button)
let previous = '' beforeNavigate(({ from }) => {
page.subscribe(value => { $previousPage = from.pathname
$previousPage = previous
previous = value.url.pathname
}) })
// Define page loading from navigating store // Define page loading from navigating store