惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
F
Fortinet All Blogs
B
Blog RSS Feed
Last Week in AI
Last Week in AI
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
P
Proofpoint News Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Microsoft Security Blog
Microsoft Security Blog
博客园 - 三生石上(FineUI控件)
Y
Y Combinator Blog
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
雷峰网
雷峰网
C
Check Point Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园 - 司徒正美
U
Unit 42
量子位

博客园 - sekihin

【SQLSERVER】备份还原除当前数据库~之外的其他数据库的bak备份 【前端】常用VsCode插件 React席哪个能优化 20 GitHub 仓库帮助你成为 React专家 Export a named export for each HTTP method instead.(Next.js 15) Error: Attempted to call generateViewport() from the server (Next.js 15) [cause]: TypeError: e_.createContext is not a function (Next.js 15) Cursor - AI代码编辑器的使用指南 Next.js项目中.prettierrc.json的配置 Next.js项目中.eslintrc.js的配置 nvm: Node Version Manager PHP slim 部署Apache NestJS 部署Apache NestJS导出API文档 ChatGPT plugins Obisidian plugins Build nest.js by tsconfig.json Data Transfer Objects (DTOs) in NestJS TypeError: stringWidth is not a function
Error occurred prerendering page "/_not-found"....
sekihin · 2025-01-05 · via 博客园 - sekihin

我们需要更新 组件,改用 的 Link 组件而不是 react-router-dom 的 Link 组件。以下是解决方法:

这样可以确保组件更好地适应 的框架,避免不兼容的问题。

# 错误的代码

'use client'

import React from 'react'
import { Box, Avatar, Typography, IconButton, Tooltip, useTheme } from '@mui/material'
import AlbumOutlinedIcon from '@mui/icons-material/AlbumOutlined'
import { Link } from 'react-router-dom'

interface ProfileProps {
  userName?: string
  designation?: string
  userimg?: string
  isCollapse?: boolean
}

export const Profile = React.forwardRef<HTMLDivElement, ProfileProps>(
  ({ userName = '', designation = '', userimg = '', isCollapse = false }, ref) => {
    const theme = useTheme()
    return (
      <Box>
        {isCollapse ? (
          ''
        ) : (
          <Box
            display={'flex'}
            alignItems='center'
            gap={2}
            sx={{ m: 3, p: 2, borderRadius: '8px', bgcolor: theme.palette.secondary.main + 20 }}
          >
            <Avatar alt='Remy Sharp' src={userimg} />

            <Box>
              <Typography variant='h6'>{userName}</Typography>
              <Typography variant='caption' color='textSecondary'>
                {designation}
              </Typography>
            </Box>
            <Box sx={{ ml: 'auto' }}>
              <Tooltip title='Logout' placement='top'>
                <Link to='/'>
                  <IconButton color='primary' aria-label='logout' size='small'>
                    <AlbumOutlinedIcon />
                  </IconButton>
                </Link>
              </Tooltip>
            </Box>
          </Box>
        )}
      </Box>
    )
  }
)

Profile.displayName = 'Profile'


# 正确的代码

'use client'

import React from 'react'
import { Box, Avatar, Typography, IconButton, Tooltip, useTheme } from '@mui/material'
import AlbumOutlinedIcon from '@mui/icons-material/AlbumOutlined'
import Link from 'next/link'

interface ProfileProps {
  userName?: string
  designation?: string
  userimg?: string
  isCollapse?: boolean
}

export const Profile = React.forwardRef<HTMLDivElement, ProfileProps>(
  ({ userName = '', designation = '', userimg = '', isCollapse = false }, ref) => {
    const theme = useTheme()
    return (
      <Box>
        {isCollapse ? (
          ''
        ) : (
          <Box
            display={'flex'}
            alignItems='center'
            gap={2}
            sx={{ m: 3, p: 2, borderRadius: '8px', bgcolor: theme.palette.secondary.main + 20 }}
          >
            <Avatar alt='Remy Sharp' src={userimg} />

            <Box>
              <Typography variant='h6'>{userName}</Typography>
              <Typography variant='caption' color='textSecondary'>
                {designation}
              </Typography>
            </Box>
            <Box sx={{ ml: 'auto' }}>
              <Tooltip title='Logout' placement='top'>
                <Link href='/'>
                  <IconButton color='primary' aria-label='logout' size='small'>
                    <AlbumOutlinedIcon />
                  </IconButton>
                </Link>
              </Tooltip>
            </Box>
          </Box>
        )}
      </Box>
    )
  }
)

Profile.displayName = 'Profile'