关于react路由的学习总结
发布日期:2021-05-11 00:28:51 浏览次数:15 分类:精选文章

本文共 2349 字,大约阅读时间需要 7 分钟。

React Router ������������

��� React ��������������� React Router ������������

1. ������ React Router

���������������������������������

������������������ npm

���������������������������������������

npm install react-router-dom

������������������ cnpm ��� yarn

���������������������������������������������������

cnpm install react-router-dom

������

yarn add react-router-dom

2. ������ React Router ������

1. ��� ��������� ���������

import { HashRouter as Router } from 'react-router-dom';

2. ��� ������������ ���������

import { BrowserRouter } from 'react-router-dom';

������������

������������������������������������������������������������������������ React ������������������

3. ������������������

������������������������

������������������

  • exact ������������������������������������������
  • Redirect ������������������������������
  • <Switch> ������������������������������������
  • ��������������������� to ������������������������
  • ��������������������� active ���������������
  • ���������
Index
  • ��������������������� to ���������������������������
  • ������������������ active ������������

5. withRouter ������������

������

������������������������������������������

������

function withRouter(WrappedComponent) {
return function(WrappedComponent) {
return function(WrappedComponent) {
return function(WrappedComponent) {
return function(WrappedComponent, props) {
return
;
};
};
};
};
}

6. ������������������

���������������

������������������

���������������

function GoLogin() {
return (
);
}

7. ������������������

������������������URL������

// ������������������������������������
// ���������������
const id = props.match.params.id;

������������URL ������������������

// ������������������ URL ������������
������

������������

���������������������������������������������������������������

8. ������������������������

���������������

< NavBar>
< NavLink to="/index">������ |
< NavLink to="/login">������

������������������

(
...
)} />

������������������������������������������������ React ������������������������������������������������������������������������������������������

上一篇:react生命周期的学习与总结
下一篇:react脚手架知识记录

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年04月22日 17时15分26秒