-
Notifications
You must be signed in to change notification settings - Fork 36
/
AsyncTabbedRouter.js
49 lines (43 loc) · 1.51 KB
/
AsyncTabbedRouter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from 'react';
import pMinDelay from 'p-min-delay';
import loadable from '@loadable/component';
import classNames from 'classnames/bind';
import { Route, useHistory, useLocation } from 'react-router-dom';
import { Tab, Tabs } from 'react-tabify';
import ChunkLoadingIcon from '~components/Sections/ReactRouter/ChunkLoadingIcon';
const DELAY = 500;
const options = {
fallback: <ChunkLoadingIcon />,
};
const AsyncIncrement = loadable(
() => pMinDelay(import('~components/Sections/ReactRouter/Routes/IncrementRoute'), DELAY),
options
);
const AsyncDecrement = loadable(
() => pMinDelay(import('~components/Sections/ReactRouter/Routes/DecrementRoute'), DELAY),
options
);
const AsyncReset = loadable(
() => pMinDelay(import('~components/Sections/ReactRouter/Routes/ResetRoute'), DELAY),
options
);
const AsyncTabbedRouter = () => {
const location = useLocation();
const history = useHistory();
return (
<div className="notification m-t-sm">
<Tabs id="router-example-tabs" activeKey={location.pathname} onSelect={(eventKey) => history.push(eventKey)}>
<Tab eventKey="/" label="Increment">
<Route exact path="/" component={AsyncIncrement} />
</Tab>
<Tab eventKey="/decrement" label="Decrement">
<Route exact path="/decrement" component={AsyncDecrement} />
</Tab>
<Tab eventKey="/reset" label="Reset">
<Route exact path="/reset" component={AsyncReset} />
</Tab>
</Tabs>
</div>
);
};
export default AsyncTabbedRouter;