Skip to content

Commit acc815e

Browse files
committed
fix: remove route state replace
Signed-off-by: Innei <[email protected]>
1 parent 613d684 commit acc815e

File tree

3 files changed

+4
-33
lines changed

3 files changed

+4
-33
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ next-env.d.ts
3636
.env
3737
.idea
3838

39-
4039
.vscode/sftp.json
40+
41+
src/app/dev

src/components/modules/peek/NotePreview.tsx

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQuery } from '@tanstack/react-query'
2-
import { useEffect, useMemo } from 'react'
2+
import { useMemo } from 'react'
33
import { atom } from 'jotai'
44
import type { NoteWrappedPayload } from '@mx-space/api-client'
55
import type { FC } from 'react'
@@ -36,21 +36,6 @@ export const NotePreview: FC<NotePreviewProps> = (props) => {
3636
...queries.note.byNid(props.noteId.toString()),
3737
})
3838

39-
useEffect(() => {
40-
const currentState = history.state
41-
const currentLocation = window.location.href
42-
const nextUrl = new URL(currentLocation)
43-
nextUrl.pathname = `/notes/${props.noteId}`
44-
const nextUrlString = nextUrl.href
45-
46-
// 虽然但是,这样浏览器的前进后退会有问题
47-
// 如果用 NextJS 的 parallel-routes 情况太复杂
48-
history.replaceState(null, '', nextUrlString)
49-
return () => {
50-
history.replaceState(currentState, '', currentLocation)
51-
}
52-
}, [props.noteId])
53-
5439
const overrideAtom = useMemo(() => atom(null! as NoteWrappedPayload), [])
5540
if (isLoading) return <Loading className="w-full" useDefaultLoadingText />
5641
if (!data) return null

src/components/modules/peek/PostPreview.tsx

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useQuery } from '@tanstack/react-query'
2-
import { useEffect, useMemo } from 'react'
2+
import { useMemo } from 'react'
33
import Balancer from 'react-wrap-balancer'
44
import { atom } from 'jotai'
55
import type { PostModel } from '@mx-space/api-client'
@@ -34,21 +34,6 @@ export const PostPreview: FC<PostPreviewProps> = (props) => {
3434
...queries.post.bySlug(category, slug),
3535
})
3636

37-
useEffect(() => {
38-
const currentState = history.state
39-
const currentLocation = window.location.href
40-
const nextUrl = new URL(currentLocation)
41-
nextUrl.pathname = `/posts/${category}/${slug}`
42-
const nextUrlString = nextUrl.href
43-
44-
// 虽然但是,这样浏览器的前进后退会有问题
45-
// 如果用 NextJS 的 parallel-routes 情况太复杂
46-
history.replaceState(null, '', nextUrlString)
47-
return () => {
48-
history.replaceState(currentState, '', currentLocation)
49-
}
50-
}, [category, slug])
51-
5237
const overrideAtom = useMemo(() => atom(null! as PostModel), [])
5338
if (isLoading) return <Loading className="w-full" useDefaultLoadingText />
5439
if (!data) return null

0 commit comments

Comments
 (0)