1. 使用react-router-dom
import { BrowserRouter, Route } from 'react-router-dom'
ReactDOM.render(
<BrowserRouter>
<Route path="/" component={App}>
<Route path="/test" component={TestPage} />
</Route>
</BrowserRouter>,
document.getElementById('root')
)
注意4x之后已经不使用react-router了
2. 使用fragment
<React.Fragment>
{//...}
</React.Fragment>
3. 使用标签内样式
class App extends Component {
constructor(props) {
super(props)
this.container = {
color: 'red',
display: 'flex',
flexFlow: 'row nowrap',
alignItems: 'center'
}
}
render() {
return (
<div className="App" style={this.container}>
<span>this is app</span>
</div>
)
}
}