无法从模块“react-router”加载文件“./dom” - React router dom

问题描述 投票:0回答:1

我已经安装了最新的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} />);   i am getting and error like 

@parcel/core:无法解析“react-router/dom” './node_modules/react-router-dom/dist/index.mjs' D:\Namsthe 颂歌模块 eact-router-dom\dist\index.mjs:13:48 12 | //索引.ts

13 |从“react-router/dom”导入{ HydratedRouter, RouterProvider }; | ^^^^^^^^^^^^^^^^^^^^ 14 |从“react-router”导出*; 15 | 15出口 { @parcel/resolver-default: 无法从模块加载文件“./dom” “反应路由器”

任何帮助将不胜感激。

reactjs react-router react-router-dom
1个回答
0
投票

React-Router 7 确实改变了他们组织代码的方式。

RouterProvider
组件不是从
react-router-dom
导出的,它来自更深层嵌套的包,特定于平台,例如特定于 DOM,导入
react-router/dom
。将导入更新为
react-router
。在 v7 中,
react-router
是主要入口点。

import {
  createBrowserRouter as Router,
  RouterProvider
} from "react-router";

欲了解完整详情,请参阅:

© www.soinside.com 2019 - 2024. All rights reserved.