小编ais*_*ais的帖子

Next.js 13 中 URL 的哈希值发生变化

是否可以在 Next.js 13v 应用程序中监视 #hash?

我做错了什么?看起来“hashchange”事件根本不起作用——仅适用于第一个应用程序渲染。

现在我正在尝试这样做,但它不起作用:

我的布局.tsx:

import './globals.css'
import './page.css'
import type { Metadata } from 'next'
import { TheMenu } from '@/components/TheMenu'

export const metadata: Metadata = {
    title: 'Test app',
    description: 'Generated by create next app'
}

export default function RootLayout({ children }: { children: React.ReactNode }) {
    return (
        <html>
            <body>
                {children}
                <TheMenu />
            </body>
        </html>
    )
}

Run Code Online (Sandbox Code Playgroud)

我的 TheMenu.tsx 组件 - 实际上更改了 #hash:

'use client'

import './menu.css'
import Link from 'next/link'
import route from …
Run Code Online (Sandbox Code Playgroud)

reactjs next.js react-hooks next.js13

6
推荐指数
0
解决办法
448
查看次数

标签 统计

next.js ×1

next.js13 ×1

react-hooks ×1

reactjs ×1