未捕获的类型错误:无法解构“React2.useContext(...)”的属性“basename”,因为它为空[重复]

2024-01-10

我面临着

Uncaught TypeError: Cannot destructure property 'basename' of 'React2.useContext(...)' as it is null.

In the Link代码的组成部分:

import React, { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';

import { styles } from '../styles';
import { navLinks } from '../constansts';
import { logo, menu, close } from '../assets';

const Navbar = () => {
  const [active, setActive] = useState('');
  return (
    <nav className={`${styles.paddingX} w-full flex items-center py-5 fixed top-0 z-20     bg-primary`}>
      <div className="w-full flex justify-between items-center max-w-7x1 max-auto">
        <Link
          to="/"
          className="flex items-center gap-2"
          onClick={() => {
            setActive('');
            window.scrollTo(0, 0);
          }}
        >
          <img alt="logo" />
        </Link>
      </div>
    </nav>
  );
};

export default Navbar;

我不知道如何解决它。谁能告诉我如何修复它吗?


你正在使用Link来自react-router-dom,但是你的应用程序没有被BrowserRouter. Your index.js:

import { BrowserRouter } from 'react-router-dom'

render(
  <BrowserRouter>
    <App />
  </BrowserRouter>,
  document.getElementById('root')
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

未捕获的类型错误:无法解构“React2.useContext(...)”的属性“basename”,因为它为空[重复] 的相关文章

随机推荐