React对比Vue(06 路由的对比)

其实差不多,

都需要先安装路由

React  先安装  

cnpm install react-router-dom --save
在再根组件引入
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
这个严格匹配要注意(vue没有好像)
 
 

这个动态路由传值,对应 的组件获取值 在DidMount里面去获取  

this.props.match.params
vue的话是this.$route.params.xx或者query.xx   详情看https://www.cnblogs.com/zhangruiqi/p/9412539.html

react获取get传值的话可以安装url

模块,方便易用贬值

********************************************************************************************************当然平时都用的是点击事件去跳转路由******************************************************************************************************************************************************************

vue中  

this.$router.push();

React 4.x router 中是:this.props.history.push('/xxx') 


原文地址:https://www.cnblogs.com/myfirstboke/p/10494227.html