最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught TypeError: (0 , _reactRouterDom.useNavigate) is not a function - Stack Overflow

programmeradmin0浏览0评论

I have been seeing this error from today while creating a new app. I knew there were few changes with the react-router-dom new version and so have installed the older version.

"react-router-dom": "^5.2.0"

Not sure what is wrong.

Code of the App ponent

import { Container } from 'react-bootstrap';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import Header from './ponents/Header';
import Footer from './ponents/Footer';
import LoginScreen from './screens/LoginScreen'


const App = () => {
  return(
    <Router>
      <Header />
          <main className='py-3'>
            <Container>
                <Route path='/' ponent={LoginScreen} />
            </Container>
          </main>
      <Footer />
    </Router>
    ) 

Can anyone please help me with this? Please let me know if any other details have to be added.

I have been seeing this error from today while creating a new app. I knew there were few changes with the react-router-dom new version and so have installed the older version.

"react-router-dom": "^5.2.0"

Not sure what is wrong.

Code of the App ponent

import { Container } from 'react-bootstrap';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import Header from './ponents/Header';
import Footer from './ponents/Footer';
import LoginScreen from './screens/LoginScreen'


const App = () => {
  return(
    <Router>
      <Header />
          <main className='py-3'>
            <Container>
                <Route path='/' ponent={LoginScreen} />
            </Container>
          </main>
      <Footer />
    </Router>
    ) 

Can anyone please help me with this? Please let me know if any other details have to be added.

Share Improve this question edited Dec 16, 2021 at 7:36 Lin Du 103k136 gold badges334 silver badges567 bronze badges asked Dec 15, 2021 at 17:42 KiranKiran 471 gold badge1 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 2

From the migration guide upgrading/v5#use-usenavigate-instead-of-usehistory, useNavigate hook is added for react-router v6.

Please check if there is any ponent that uses this hook. For react-router v5, you should use useHistory() to get the history object and perform the navigation.

发布评论

评论列表(0)

  1. 暂无评论