gpt4 book ai didi

javascript - react : 'Redirect' is not exported from 'react-router-dom'

转载 作者:行者123 更新时间:2023-12-04 12:13:27 24 4
gpt4 key购买 nike

运行 npm run start 时出现以下错误在终端。

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


我重新安装了 node_modules , react-router-dom , react-router .还重新启动了终端和我的计算机,但问题仍然存在。
我的代码:
import React from 'react';
import { Switch, Redirect } from 'react-router-dom';

import { RouteWithLayout } from './components';
import { Minimal as MinimalLayout } from './layouts';

import {
Login as LoginView,
Dashboard as DashboardView,
NotFound as NotFoundView
} from './views';

const Routes = () => {
return (
<Switch>
<Redirect
exact
from="/"
to="/dashboard"
/>
<RouteWithLayout
component={routeProps => <LoginView {...routeProps} data={data} />}
exact
layout={MinimalLayout}
path="/login"
/>
<Redirect to="/not-found" />
</Switch>
);
};

export default Routes;
这是我的 package.json进口:
"react-router": "^6.0.0-beta.0",
"react-router-dom": "^6.0.0-beta.0",

最佳答案

对于 react-router-dom v6,只需替换 RedirectNavigate

import { Navigate } from 'react-router-dom';
.
.
.
{ component: () => <Navigate to="/404" /> }

关于javascript - react : 'Redirect' is not exported from 'react-router-dom' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63690695/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com