mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-08 01:53:34 +08:00
chore: Upgrade react router v6 (#32821)
* chore: upgrade react-router to v6 close #32809 close #32774 * fix test * fix test * fix test * fix test
This commit is contained in:
parent
43569b9354
commit
3f495bb56d
@ -1,3 +1,3 @@
|
|||||||
import demoTest from '../../../tests/shared/demoTest';
|
import demoTest from '../../../tests/shared/demoTest';
|
||||||
|
|
||||||
demoTest('breadcrumb', { skip: ['router.md', 'router-4.md'] });
|
demoTest('breadcrumb', { skip: ['react-router.md'] });
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { imageDemoTest } from '../../../tests/shared/imageTest';
|
import { imageDemoTest } from '../../../tests/shared/imageTest';
|
||||||
|
|
||||||
describe('Breadcrumb image', () => {
|
describe('Breadcrumb image', () => {
|
||||||
imageDemoTest('breadcrumb', { skip: ['router-4.md'] });
|
imageDemoTest('breadcrumb', { skip: ['react-router.md'] });
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Route, Switch, Link, withRouter, MemoryRouter } from 'react-router-dom';
|
import { Route, Routes, Link, useLocation, useNavigate, MemoryRouter } from 'react-router-dom';
|
||||||
import { mount } from 'enzyme';
|
import { mount } from 'enzyme';
|
||||||
import Breadcrumb from '../index';
|
import Breadcrumb from '../index';
|
||||||
|
|
||||||
@ -32,12 +32,10 @@ describe('react router', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// https://github.com/airbnb/enzyme/issues/875
|
// https://github.com/airbnb/enzyme/issues/875
|
||||||
it('react router 4', () => {
|
it('react router 6', () => {
|
||||||
if (process.env.REACT === '15') {
|
const Home = () => {
|
||||||
return;
|
const location = useLocation();
|
||||||
}
|
const navigate = useNavigate();
|
||||||
const Home = withRouter(props => {
|
|
||||||
const { location, history } = props;
|
|
||||||
const pathSnippets = location.pathname.split('/').filter(i => i);
|
const pathSnippets = location.pathname.split('/').filter(i => i);
|
||||||
const extraBreadcrumbItems = pathSnippets.map((_, index) => {
|
const extraBreadcrumbItems = pathSnippets.map((_, index) => {
|
||||||
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
|
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
|
||||||
@ -55,17 +53,17 @@ describe('react router', () => {
|
|||||||
return (
|
return (
|
||||||
<div className="demo">
|
<div className="demo">
|
||||||
<div className="demo-nav">
|
<div className="demo-nav">
|
||||||
<a onClick={() => history.push('/')}>Home</a>
|
<a onClick={() => navigate('/')}>Home</a>
|
||||||
<a onClick={() => history.push('/apps')}>Application List</a>
|
<a onClick={() => navigate('/apps')}>Application List</a>
|
||||||
</div>
|
</div>
|
||||||
<Switch>
|
<Routes>
|
||||||
<Route path="/apps" component={Apps} />
|
<Route path="/apps" component={Apps} />
|
||||||
<Route render={() => <span>Home Page</span>} />
|
<Route render={() => <span>Home Page</span>} />
|
||||||
</Switch>
|
</Routes>
|
||||||
<Breadcrumb>{breadcrumbItems}</Breadcrumb>
|
<Breadcrumb>{breadcrumbItems}</Breadcrumb>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<MemoryRouter initialEntries={['/']} initialIndex={0}>
|
<MemoryRouter initialEntries={['/']} initialIndex={0}>
|
||||||
<Home />
|
<Home />
|
||||||
|
@ -3,20 +3,20 @@ order: 3
|
|||||||
iframe: 200
|
iframe: 200
|
||||||
reactRouter: react-router-dom
|
reactRouter: react-router-dom
|
||||||
title:
|
title:
|
||||||
zh-CN: 其它路由
|
zh-CN: react-router V6
|
||||||
en-US: Other Router Integration
|
en-US: react-router V6
|
||||||
---
|
---
|
||||||
|
|
||||||
## zh-CN
|
## zh-CN
|
||||||
|
|
||||||
和 `react-router@4+`,或其他路由进行结合使用。
|
与 `react-router@6+` 结合使用,生成和路由绑定的面包屑。
|
||||||
|
|
||||||
## en-US
|
## en-US
|
||||||
|
|
||||||
Used together with `react-router@4+` or other router.
|
Used together with `react-router@6+`.
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
import { HashRouter as Router, Route, Switch, Link, withRouter } from 'react-router-dom';
|
import { HashRouter, Route, Routes, Link, useLocation } from 'react-router-dom';
|
||||||
import { Breadcrumb, Alert } from 'antd';
|
import { Breadcrumb, Alert } from 'antd';
|
||||||
|
|
||||||
const Apps = () => (
|
const Apps = () => (
|
||||||
@ -37,8 +37,8 @@ const breadcrumbNameMap = {
|
|||||||
'/apps/1/detail': 'Detail',
|
'/apps/1/detail': 'Detail',
|
||||||
'/apps/2/detail': 'Detail',
|
'/apps/2/detail': 'Detail',
|
||||||
};
|
};
|
||||||
const Home = withRouter(props => {
|
const Home = props => {
|
||||||
const { location } = props;
|
const location = useLocation();
|
||||||
const pathSnippets = location.pathname.split('/').filter(i => i);
|
const pathSnippets = location.pathname.split('/').filter(i => i);
|
||||||
const extraBreadcrumbItems = pathSnippets.map((_, index) => {
|
const extraBreadcrumbItems = pathSnippets.map((_, index) => {
|
||||||
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
|
const url = `/${pathSnippets.slice(0, index + 1).join('/')}`;
|
||||||
@ -59,20 +59,20 @@ const Home = withRouter(props => {
|
|||||||
<Link to="/">Home</Link>
|
<Link to="/">Home</Link>
|
||||||
<Link to="/apps">Application List</Link>
|
<Link to="/apps">Application List</Link>
|
||||||
</div>
|
</div>
|
||||||
<Switch>
|
<Routes>
|
||||||
<Route path="/apps" component={Apps} />
|
<Route path="/apps" component={Apps} />
|
||||||
<Route render={() => <span>Home Page</span>} />
|
<Route render={() => <span>Home Page</span>} />
|
||||||
</Switch>
|
</Routes>
|
||||||
<Alert style={{ margin: '16px 0' }} message="Click the navigation above to switch:" />
|
<Alert style={{ margin: '16px 0' }} message="Click the navigation above to switch:" />
|
||||||
<Breadcrumb>{breadcrumbItems}</Breadcrumb>
|
<Breadcrumb>{breadcrumbItems}</Breadcrumb>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Router>
|
<HashRouter>
|
||||||
<Home />
|
<Home />
|
||||||
</Router>,
|
</HashRouter>,
|
||||||
mountNode,
|
mountNode,
|
||||||
);
|
);
|
||||||
```
|
```
|
@ -152,7 +152,7 @@
|
|||||||
"scroll-into-view-if-needed": "^2.2.25"
|
"scroll-into-view-if-needed": "^2.2.25"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ant-design/bisheng-plugin": "^2.3.0",
|
"@ant-design/bisheng-plugin": "^3.0.0",
|
||||||
"@ant-design/hitu": "^0.0.0-alpha.13",
|
"@ant-design/hitu": "^0.0.0-alpha.13",
|
||||||
"@ant-design/tools": "^14.0.0-alpha.3",
|
"@ant-design/tools": "^14.0.0-alpha.3",
|
||||||
"@docsearch/css": "^3.0.0-alpha.39",
|
"@docsearch/css": "^3.0.0-alpha.39",
|
||||||
@ -254,7 +254,7 @@
|
|||||||
"react-infinite-scroll-component": "^6.1.0",
|
"react-infinite-scroll-component": "^6.1.0",
|
||||||
"react-intl": "^5.20.4",
|
"react-intl": "^5.20.4",
|
||||||
"react-resizable": "^3.0.1",
|
"react-resizable": "^3.0.1",
|
||||||
"react-router-dom": "^5.0.1",
|
"react-router-dom": "^6.0.2",
|
||||||
"react-sortable-hoc": "^2.0.0",
|
"react-sortable-hoc": "^2.0.0",
|
||||||
"react-sticky": "^6.0.3",
|
"react-sticky": "^6.0.3",
|
||||||
"react-test-renderer": "^17.0.1",
|
"react-test-renderer": "^17.0.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user