import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter as Router, Route, Link} from 'react-router-dom';
import 'font-awesome/css/font-awesome.min.css';
import './index.css';
import './index.scss';
class A extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<h1>Component A</h1>
<p>参数:{this.props.match.params.id}</p>
</div>
)
}
}
class B extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>Component B</div>
)
}
}
class Wrapper extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<p><Link to="/a">组件A</Link></p>
<p><Link to="/a/123">带参数的组件A</Link></p>
<p><Link to="/b">组件B</Link></p>
{this.props.children}
</div>
)
}
}
ReactDOM.render(
<Router>
<Wrapper>
<Route path="/a/:id" component={A}></Route>
<Route path="/b" component={B}></Route>
</Wrapper>
</Router>,
document.getElementById('app')
);
深入了解React(十九、路由5-带参数1 )
最新推荐文章于 2024-04-20 03:21:18 发布