|
1 | 1 | import { hot } from 'react-hot-loader'; |
2 | 2 | import React, { Component, Suspense } from 'react'; |
3 | | -import { BrowserRouter, Switch, Route } from 'react-router-dom'; |
| 3 | +import { BrowserRouter, Switch, Route, Redirect } from 'react-router-dom'; |
4 | 4 | import { ApolloProvider } from '@apollo/client'; |
5 | 5 | import { ApolloClient } from 'apollo-client'; |
6 | 6 | import { HttpLink } from 'apollo-link-http'; |
@@ -90,19 +90,31 @@ class App extends Component { |
90 | 90 | <CssBaseline /> |
91 | 91 | <BrowserRouter> |
92 | 92 | <Switch> |
93 | | - {routes.map(({ path, exact, component: Component, ...props }) => ( |
94 | | - <Route |
95 | | - key={path} |
96 | | - path={path} |
97 | | - exact={exact} |
98 | | - render={({ staticContext, ...renderProps }) => ( |
99 | | - <Suspense |
100 | | - fallback={<Spinner className={classes.spinner} />}> |
101 | | - <Component {...renderProps} {...props} /> |
102 | | - </Suspense> |
103 | | - )} |
104 | | - /> |
105 | | - ))} |
| 93 | + {routes.map(({ path, exact, redirect, component: Component, ...props }) => |
| 94 | + redirect ? ( |
| 95 | + <Route |
| 96 | + key={path} |
| 97 | + path={path} |
| 98 | + render={({ location }) => ( |
| 99 | + <Redirect |
| 100 | + to={{ pathname: redirect, search: location.search }} |
| 101 | + /> |
| 102 | + )} |
| 103 | + /> |
| 104 | + ) : ( |
| 105 | + <Route |
| 106 | + key={path} |
| 107 | + path={path} |
| 108 | + exact={exact} |
| 109 | + render={({ staticContext, ...renderProps }) => ( |
| 110 | + <Suspense |
| 111 | + fallback={<Spinner className={classes.spinner} />}> |
| 112 | + <Component {...renderProps} {...props} /> |
| 113 | + </Suspense> |
| 114 | + )} |
| 115 | + /> |
| 116 | + ) |
| 117 | + )} |
106 | 118 | </Switch> |
107 | 119 | </BrowserRouter> |
108 | 120 | </MuiThemeProvider> |
|
0 commit comments