-
Notifications
You must be signed in to change notification settings - Fork 97
/
customRoute.js
28 lines (24 loc) 路 1.02 KB
/
customRoute.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
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import ErrorBoundary from '../errorBoundary';
import offlineStyle from '../offlineWrapper/offlineWrapper.css';
import Piwik from '../../utils/piwik';
import routes from '../../constants/routes';
const CustomRoute = ({
path, component, isPrivate, exact,
settings,
isAuthenticated, pathSuffix = '', pathPrefix = '', t, ...rest
}) => {
const { pathname, search } = rest.history.location;
const fullPath = pathPrefix + path + pathSuffix;
Piwik.tracking(rest.history, settings);
return ((isPrivate && isAuthenticated) || !isPrivate ?
<main className={`${isPrivate ? offlineStyle.disableWhenOffline : ''} offlineWrapper`}>
<ErrorBoundary errorMessage={t('An error occoured while rendering this page')}>
<Route path={fullPath} component={component} exact={exact} />
</ErrorBoundary>
</main>
: <Redirect to={`${routes.loginV2.path}?referrer=${pathname}${encodeURIComponent(search)}`} />
);
};
export default CustomRoute;