我已经安装了最新的react-router-dom,并在package.js中显示了它
"react-router-dom": "^7.0.2"
当我检查时
npm -v react-router-dom its showing 10.9.0
。在我的代码中
import React from "react";
import ReactDOM from "react-dom";
import Header from "./components/Header";
import Body from "./components/Body";
import About from "./components/About";
import {
createBrowserRouter as Router,
RouterProvider
} from "react-router-dom";
const AppLayout = () => {
return (
<div className="app">
<Header />
<Body />
</div>
);
};
const appRouter= createBrowserRouter ([
{ path: "/", element: <AppLayout /> },
{ path: "about", element: <About /> },
])
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<RouterProvider router= {appRouter} />);
我得到和错误一样
@包裹/核心:无法从解析“react-router/dom”
'./node_modules/react-router-dom/dist/index.mjs
D: \Namthe\node_modules\react路由器dom\dist\index.mjs:13:48 12|
//index.ts
13|从“react-router/dom”导入{HydratedOuter,RouterProvider};
|从“反应路由器”导出*;15 |出口
{@package/resolver默认值:无法从模块加载文件“./dom”
'反应路由器'