javascriptreactjsreact-router

ImportError: 'useNavigate' is not exported from 'react-router-dom'


When trying to import useNavigate from react-router-dom, I get the following error:

Attempted import error: 'useNavigate' is not exported from 'react-router-dom'.

My Import statement:

import { useNavigate } from 'react-router-dom';

Solution

  • You are trying to use the latest features of react-router.
    Please make sure that you installed the react-router-dom@6.0.0-alpha.2 .

    It is React Router v6 which gives you a useNavigate hook

    Please refer here for further reading from the React Router team

    Two quick ways to check the version: