mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-19 11:19:14 +08:00
feat: 404 auto redirect to /
This commit is contained in:
parent
b1fb9d7285
commit
ae242300d7
@ -2,9 +2,9 @@ import { metadata, sectionIds } from "@shared/data"
|
|||||||
import type { SectionID } from "@shared/types"
|
import type { SectionID } from "@shared/types"
|
||||||
import { Link, createFileRoute } from "@tanstack/react-router"
|
import { Link, createFileRoute } from "@tanstack/react-router"
|
||||||
import clsx from "clsx"
|
import clsx from "clsx"
|
||||||
import { useAtom } from "jotai"
|
import { useAtom, useAtomValue } from "jotai"
|
||||||
import { useEffect } from "react"
|
import { useEffect, useMemo } from "react"
|
||||||
import { currentSectionIDAtom } from "~/atoms"
|
import { currentSectionIDAtom, focusSourcesAtom } from "~/atoms"
|
||||||
import { Dnd } from "~/components/section/Dnd"
|
import { Dnd } from "~/components/section/Dnd"
|
||||||
import { Pure } from "~/components/section/Pure"
|
import { Pure } from "~/components/section/Pure"
|
||||||
|
|
||||||
@ -16,11 +16,23 @@ export const Route = createFileRoute("/")({
|
|||||||
})
|
})
|
||||||
|
|
||||||
function IndexComponent() {
|
function IndexComponent() {
|
||||||
const { section: id = "focus" } = Route.useSearch()
|
const { section } = Route.useSearch()
|
||||||
|
const focusSources = useAtomValue(focusSourcesAtom)
|
||||||
|
const nav = Route.useNavigate()
|
||||||
const [currentSectionID, setCurrentSectionID] = useAtom(currentSectionIDAtom)
|
const [currentSectionID, setCurrentSectionID] = useAtom(currentSectionIDAtom)
|
||||||
|
const id = useMemo(() => {
|
||||||
|
if (sectionIds.includes(section)) return section
|
||||||
|
else return focusSources.length ? "focus" : "social"
|
||||||
|
}, [section, focusSources])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrentSectionID(id)
|
setCurrentSectionID(id)
|
||||||
}, [setCurrentSectionID, id])
|
nav({
|
||||||
|
to: "/",
|
||||||
|
search: { section: id },
|
||||||
|
replace: true,
|
||||||
|
})
|
||||||
|
}, [setCurrentSectionID, id, nav])
|
||||||
|
|
||||||
return currentSectionID === id && (
|
return currentSectionID === id && (
|
||||||
<div className="flex flex-col justify-center items-center">
|
<div className="flex flex-col justify-center items-center">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user