简体   繁体   English

路由器可能只有一个子元素

[英]A Router may have only one child element

Im try to learn react routing I created a project and in my index.js file i change my code as below 我试着学习反应路由我创建了一个项目,在我的index.js文件中我改变了我的代码,如下所示

import React from 'react';
import ReactDOM from 'react-dom';

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

import App from './components/App';
import Signin from './components/Signin';
import Signup from './components/Signup';

ReactDOM.render(
    <Router path="/">
        <Route path="/app" component={App} />
        <Route path="/signup" component={Signup} />                                                                    
        <Route path="/signin" component={Signin} />
    </Router>, document.getElementById('root')
);

but it gives an error like below 但它给出了如下错误

Module not found: Can't resolve 'react-router-dom' in 'D:\\REACT\\react-crud\\src' 找不到模块:无法解析'D:\\ REACT \\ react-crud \\ src'中的'react-router-dom'

Install your package react-router-dom using npm install -S react-router-dom and also you can have one child for the Router. 使用npm install -S react-router-dom安装你的包react-router-dom ,你也可以为路由器安装one child节点。 Wrap you Routes within a div/ Switch whichever is suited to your needs 将您的路由包裹在div/ Switch以满足您的需求

ReactDOM.render(
    <Router>
       <div>
        <Route path="/app" component={App} />
        <Route path="/signup" component={Signup} />                                                                    
        <Route path="/signin" component={Signin} />
       </div>
    </Router>, document.getElementById('root')
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM