feat: use beforeNavigate to allow users to click back
This commit is contained in:
1 parent
903ab38977
commit
4113c1108c
1 file changed
+8
-2
@@ -19,7 +19,7 @@
|
|||||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { instance } from '$lib/instance.js'
|
import { instance } from '$lib/instance.js'
|
||||||
import { afterNavigate, goto } from '$app/navigation'
|
import { afterNavigate, beforeNavigate, goto } from '$app/navigation'
|
||||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||||
import Link from '$lib/components/input/Link.svelte'
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
@@ -40,7 +40,11 @@
|
|||||||
|
|
||||||
afterNavigate(async () => {
|
afterNavigate(async () => {
|
||||||
// reactivity hack
|
// reactivity hack
|
||||||
|
|
||||||
post = data.post
|
post = data.post
|
||||||
|
})
|
||||||
|
|
||||||
|
beforeNavigate(async () => {
|
||||||
if (
|
if (
|
||||||
$page.params.instance.toLowerCase() != $instance.toLowerCase() &&
|
$page.params.instance.toLowerCase() != $instance.toLowerCase() &&
|
||||||
$profile?.jwt
|
$profile?.jwt
|
||||||
@@ -58,7 +62,9 @@
|
|||||||
|
|
||||||
if (res.post) {
|
if (res.post) {
|
||||||
removeToast(id)
|
removeToast(id)
|
||||||
goto(`/post/${$instance}/${res.post.post.id}`)
|
goto(`/post/${$instance}/${res.post.post.id}`, {}).then(() =>
|
||||||
|
removeToast(id)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
removeToast(id)
|
removeToast(id)
|
||||||
|
|||||||
Reference in new issue
Block a user