React-router 页面跳转的三种方式

方式一:

import { withRouter } from 'react-router-dom'

class Index extends Component {
	...
	changePage = () => {
		let { history } = this.props
		history.push({pathname: '/Home'})
	}
}
...

export default withRouter(Index)

方式二:

history.js:

import { createHistory } from 'history';

export default createHistory();

Index.js:

import history from './history';

export default class Index extends Component {
...
	changePage = () => {
		history.push({pathname: '/Home'})
	}
...
}

方式三:

import React, { Component } from 'react'
import { NavLink } from "react-router-dom";

class Home extends Component {
  constructor(props){
    super(props)
  };
  render(){
    return (
      
跳转到 ShppingCart
跳转到 Classify

{this.props.children}
) } } export default Home

你可能感兴趣的:(React)