我正在使用react-router-dom并面临这个问题。我该如何摆脱呢?

时间:2019-12-11 11:25:09

标签: reactjs react-router

我已经在node_modules文件夹中安装了react-router-dom,并且每当我导入react-router-dom时都会显示此错误

  

./ src / index.js找不到模块:您试图导入   ../node_modules/rect-router-dom不在项目范围内   src /目录。不支持src /以外的相对导入。

我如何摆脱它?

index.js文件中的代码如下

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import './index.css'; 
import App from './App'; 
import About from './pages/About' 
import Contact from './pages/Contact' 
import { Route, Link, BrowseRouter as Router } from 'rect-router-dom'; 
import * as serviceWorker from './serviceWorker'; 

const myrouter = ( <Router> </Router> ) 
ReactDOM.render(myrouter, document.getElementById('root')); 
serviceWorker.unregister();

1 个答案:

答案 0 :(得分:0)

这是导入它的正确方法

import { Route, Link, BrowseRouter as Router } from 'react-router-dom';