react-router4 跳转其他组件失败
怎么实现点击链接,second组件是新页面展示,而不是在当前页面展示呢!地址栏的路由对了,但是不能跳转
index.js
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { Route,BrowserRouter}from 'react-router-dom';
import registerServiceWorker from './registerServiceWorker';
import home from './components/home';
import second from './components/second'
ReactDOM.render((
<BrowserRouter>
<div>
<App>
<Route path = '/' component={home}></Route>
</App>
<Route path = '/second' component={second}></Route>
</div>
</BrowserRouter>
),document.getElementById('root'));
registerServiceWorker();
App.js
import React, { Component } from 'react';
// import logo from './logo.svg';
import './App.css';
// import {Router, Route, Link,BrowserRouter,HashRouter,hashHistory,Indexlink,Match}from 'react-router-dom';
import {Link} from 'react-router-dom'
class App extends Component {
render() {
return (
<div className="App">
<h1>hello,world</h1>
{this.props.children}
</div>
);
}
}
export default App;
home.js
import React, { Component } from 'react';
// import logo from './logo.svg';
// import {Router, Route, Link,BrowserRouter,HashRouter,hashHistory,Indexlink,Match}from 'react-router-dom';
import {Link} from 'react-router-dom'
class myHome extends Component {
render() {
return (
<div className="myHome">
<h1>home页面</h1>
<Link to="/second">点击点击</Link>
</div>
);
}
}
export default myHome;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
<Route path = '/second' component={second}></Route>
中添加exact
属性就可以了。如下:
请把错误信息和second页面的代码贴出来