admin管理员组文章数量:1334202
Im try to learn react routing I created a project and in my index.js file i change my code as below
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import App from './ponents/App';
import Signin from './ponents/Signin';
import Signup from './ponents/Signup';
ReactDOM.render(
<Router path="/">
<Route path="/app" ponent={App} />
<Route path="/signup" ponent={Signup} />
<Route path="/signin" ponent={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'
Im try to learn react routing I created a project and in my index.js file i change my code as below
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import App from './ponents/App';
import Signin from './ponents/Signin';
import Signup from './ponents/Signup';
ReactDOM.render(
<Router path="/">
<Route path="/app" ponent={App} />
<Route path="/signup" ponent={Signup} />
<Route path="/signin" ponent={Signin} />
</Router>, document.getElementById('root')
);
but it gives an error like below
Share Improve this question edited Feb 20, 2018 at 12:41 Shubham Khatri 282k58 gold badges431 silver badges411 bronze badges asked Feb 19, 2018 at 8:39 stewartstewart 472 silver badges8 bronze badges 5Module not found: Can't resolve 'react-router-dom' in 'D:\REACT\react-crud\src'
-
1
Have you installed
react-router-dom
? – Agney Commented Feb 19, 2018 at 8:40 -
1
that means you need to install the
react-router-dom
, use this:npm install --save react-router-dom
. Check this for more details: react-router-dom – Mayank Shukla Commented Feb 19, 2018 at 8:41 -
now it gives an error like
A <Router> may have only one child element
– stewart Commented Feb 19, 2018 at 8:45 -
1
@stewart wrap all the routes in a
div
, like this:<Router><div> /*all routes*/ </div></Router>
– Mayank Shukla Commented Feb 19, 2018 at 8:48 - Just put all your routes between <div> </div> or <React.Fragment></React.Fragment> – mix-fGt Commented Aug 17, 2018 at 9:54
1 Answer
Reset to default 8Install your package react-router-dom
using npm install -S react-router-dom
and also you can have one child
for the Router. Wrap you Routes within a div/
Switch
whichever is suited to your needs
ReactDOM.render(
<Router>
<div>
<Route path="/app" ponent={App} />
<Route path="/signup" ponent={Signup} />
<Route path="/signin" ponent={Signin} />
</div>
</Router>, document.getElementById('root')
);
本文标签: javascriptA Router may have only one child elementStack Overflow
版权声明:本文标题:javascript - A Router may have only one child element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742246793a2440002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论