React Router v4页面跳转
在React Router v4中 可以使用
- withRouter组件
- 使用标签
1.使用withRouter组件
withRouter组件将注入history对象作为该组件的属性
import React from 'react'
import { withRouter } from 'react-router-dom'
import { Button } from 'antd'
export const ButtonWithRouter = withRouter(({ history }) => {
console.log('history', history)
return (
<Button
type='default'
onClick={() => { history.push('/new-location') }}
>
Click Me!
</Button>
)
})
引入 import { ButtonWithRouter } from ‘./buttonWithRouter’
或者:
const ButtonWithRouter = (props) => {
console.log('props', props)
return (
<Button