feat: fix slug updating in ArticlePage component by managing curentSlug signal
This commit is contained in:
parent
32ebcff5fe
commit
55e2b34466
|
@ -1,6 +1,16 @@
|
||||||
import { RouteDefinition, RouteSectionProps, createAsync, useLocation } from '@solidjs/router'
|
import { RouteDefinition, RouteSectionProps, createAsync, useLocation } from '@solidjs/router'
|
||||||
import { HttpStatusCode } from '@solidjs/start'
|
import { HttpStatusCode } from '@solidjs/start'
|
||||||
import { ErrorBoundary, Show, Suspense, createEffect, on, onMount, Switch, Match, createSignal } from 'solid-js'
|
import {
|
||||||
|
ErrorBoundary,
|
||||||
|
Match,
|
||||||
|
Show,
|
||||||
|
Suspense,
|
||||||
|
Switch,
|
||||||
|
createEffect,
|
||||||
|
createSignal,
|
||||||
|
on,
|
||||||
|
onMount
|
||||||
|
} from 'solid-js'
|
||||||
import { FourOuFourView } from '~/components/Views/FourOuFour'
|
import { FourOuFourView } from '~/components/Views/FourOuFour'
|
||||||
import { Loading } from '~/components/_shared/Loading'
|
import { Loading } from '~/components/_shared/Loading'
|
||||||
import { gaIdentity } from '~/config'
|
import { gaIdentity } from '~/config'
|
||||||
|
@ -52,7 +62,6 @@ function ArticlePageContent(props: RouteSectionProps<ArticlePageProps>) {
|
||||||
})
|
})
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
console.debug('[ArticlePage] onMount')
|
|
||||||
if (gaIdentity && data()?.id) {
|
if (gaIdentity && data()?.id) {
|
||||||
try {
|
try {
|
||||||
await loadGAScript(gaIdentity)
|
await loadGAScript(gaIdentity)
|
||||||
|
@ -109,42 +118,39 @@ function ArticlePageContent(props: RouteSectionProps<ArticlePageProps>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ArticlePage(props: RouteSectionProps<SlugPageProps>) {
|
export default function ArticlePage(props: RouteSectionProps<SlugPageProps>) {
|
||||||
console.debug('[routes] [slug]/[...tab] props:', props)
|
const [currentSlug, setCurrentSlug] = createSignal(props.params.slug)
|
||||||
|
|
||||||
const { slug } = props.params
|
|
||||||
|
|
||||||
const [currentSlug, setCurrentSlug] = createSignal(props.params.slug);
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (props.params.slug !== currentSlug()) {
|
const newSlug = props.params.slug
|
||||||
setCurrentSlug(props.params.slug);
|
if (newSlug !== currentSlug()) {
|
||||||
|
setCurrentSlug(newSlug)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Switch fallback={<div>Loading...</div>}>
|
<Switch fallback={<div>Loading...</div>}>
|
||||||
<Match when={currentSlug().startsWith('@')}>
|
<Match when={currentSlug().startsWith('@')}>
|
||||||
<AuthorPage
|
<AuthorPage
|
||||||
{...{
|
{...({
|
||||||
...props,
|
...props,
|
||||||
params: {
|
params: {
|
||||||
...props.params,
|
...props.params,
|
||||||
slug: slug.slice(1),
|
slug: currentSlug().slice(1)
|
||||||
},
|
}
|
||||||
} as RouteSectionProps<AuthorPageProps>}
|
} as RouteSectionProps<AuthorPageProps>)}
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={currentSlug().startsWith('!')}>
|
<Match when={currentSlug().startsWith('!')}>
|
||||||
<TopicPage
|
<TopicPage
|
||||||
{...{
|
{...({
|
||||||
...props,
|
...props,
|
||||||
params: {
|
params: {
|
||||||
...props.params,
|
...props.params,
|
||||||
slug: slug.slice(1),
|
slug: currentSlug().slice(1)
|
||||||
},
|
}
|
||||||
} as RouteSectionProps<TopicPageProps>}
|
} as RouteSectionProps<TopicPageProps>)}
|
||||||
/>
|
/>
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={!currentSlug().startsWith('@') && !currentSlug().startsWith('!')}>
|
<Match when={!['@', '!'].some((prefix) => currentSlug().startsWith(prefix))}>
|
||||||
<ArticlePageContent {...props} />
|
<ArticlePageContent {...props} />
|
||||||
</Match>
|
</Match>
|
||||||
<Match when={true}>
|
<Match when={true}>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user