export 'redirect' (imported as 'redirect') was not found in 'react-router-dom'
时间: 2023-04-23 08:03:57 浏览: 1022
"export 'redirect' (imported as 'redirect') was not found in 'react-router-dom'" 的意思是在 'react-router-dom' 中找不到名为 'redirect' 的导出项。
可能是因为你在代码中使用了 'redirect',但是没有正确导入它。你需要检查你的代码,确保你已经正确地导入了 'redirect'。
如果你仍然无法解决问题,你可以尝试更新你的 'react-router-dom' 版本或者查看官方文档以获取更多帮助。
相关问题
export 'Routes' (imported as 'Routes') was not found in 'react-router-dom'
这错误是因为在使用react-router-dom时,导入的`Routes`并未在react-router-dom中找到。根据引用中的信息,可以尝试更改react-router-dom的版本号为5.x.x,并重新安装依赖项。但是根据引用中的提示,还需要手动卸载并重新安装react-router。具体做法是通过以下命令来卸载和重新安装react-router-dom和react-router:
```
npm uninstall react-router-dom react-router
npm install react-router-dom@5 react-router@5
```
这将卸载当前安装的react-router-dom和react-router,并重新安装5.x.x版本的react-router-dom和react-router,以解决`export 'Routes' (imported as 'Routes') was not found in 'react-router-dom'`的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
export 'withRouter' (imported as 'withRouter') was not found in 'react-router-dom'
The error message you encountered suggests that the named export 'withRouter' was not found in the 'react-router-dom' package. This error commonly occurs when using the latest versions of React Router, as the 'withRouter' higher-order component has been deprecated.
Instead of using 'withRouter', you can access the router props by using the 'useHistory', 'useLocation', or 'useParams' hooks provided by React Router. These hooks allow you to access the history, location, and params objects directly within your functional components.
For example, to access the history object, you can use the 'useHistory' hook:
```jsx
import { useHistory } from 'react-router-dom';
function MyComponent() {
const history = useHistory();
// Access history methods (e.g., push, replace, goBack) here
// ...
}
```
Similarly, you can use the 'useLocation' and 'useParams' hooks to access the location and params objects, respectively.
Please note that these hooks are only available in functional components. If you are using a class component, you might need to consider using a different approach or wrapping your class component with a functional component that utilizes these hooks.