1- import React , { Component } from 'react'
2- import { Switch , Route } from 'react-router-dom'
1+ import React from 'react'
2+ import { Switch , Route , Redirect } from 'react-router-dom'
33import { Provider } from 'react-redux'
44
55import GlobalStyles from './globalStyles'
@@ -9,32 +9,36 @@ import { Cart } from './pages/Cart'
99import { SignUp } from './pages/SignUp'
1010import { LogIn } from './pages/LogIn'
1111import { Account } from './pages/Account'
12+ import { NotFound } from './pages/NotFound'
1213import { PrivateRoute } from './components/PrivateRoute'
1314import { getCustomer } from './utils/customer'
1415import { configureStore } from './store'
16+ import * as routes from './routes'
1517
1618const store = configureStore ( {
1719 customer : getCustomer ( ) ,
1820} )
1921
20- class App extends Component {
21- render ( ) {
22- return (
23- < Provider store = { store } >
24- < React . Fragment >
25- < GlobalStyles />
26- < Switch >
27- < Route path = "/" exact component = { ProductList } />
28- < Route path = "/cart" component = { Cart } />
29- < Route path = "/signup" component = { SignUp } />
30- < Route path = "/login" component = { LogIn } />
31- < PrivateRoute path = "/account" component = { Account } />
32- < Route path = "/:productId" component = { ProductDetail } />
33- </ Switch >
34- </ React . Fragment >
35- </ Provider >
36- )
37- }
38- }
22+ const App = ( ) => (
23+ < Provider store = { store } >
24+ < React . Fragment >
25+ < GlobalStyles />
26+ < Switch >
27+ < Route
28+ path = { routes . HOMEPAGE }
29+ exact
30+ render = { ( ) => < Redirect to = { routes . PRODUCT_LIST } /> }
31+ />
32+ < Route path = { routes . PRODUCT_LIST } exact component = { ProductList } />
33+ < Route path = { routes . PRODUCT_DETAIL } component = { ProductDetail } />
34+ < Route path = { routes . CART } component = { Cart } />
35+ < Route path = { routes . SIGN_UP } component = { SignUp } />
36+ < Route path = { routes . LOGIN } component = { LogIn } />
37+ < PrivateRoute path = { routes . ACCOUNT } component = { Account } />
38+ < Route component = { NotFound } />
39+ </ Switch >
40+ </ React . Fragment >
41+ </ Provider >
42+ )
3943
40- export default App
44+ export { App }
0 commit comments