-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathroutes.jsx
More file actions
128 lines (120 loc) · 3.6 KB
/
routes.jsx
File metadata and controls
128 lines (120 loc) · 3.6 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* istanbul ignore file */
// NOTE!
// This file is being ignored in the test coverage report for now. It reports `0%` functions
// tested, which brings down the overall coverage and blocks CI. There are tests still, but
// we don't want it to count toward coverage until we figure out how to cover the `functions`
// metric for this file in its test.
import React, {useEffect} from 'react'
import loadable from '@loadable/component'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
import {withRouter} from 'react-router-dom'
// Components
import {Skeleton} from '@salesforce/retail-react-app/app/components/shared/ui'
import {configureRoutes} from '@salesforce/retail-react-app/app/utils/routes-utils'
const fallback = <Skeleton height="75vh" width="100%" />
// Pages
const Home = loadable(() => import('./pages/home'), {fallback})
const Login = loadable(() => import('./pages/login'), {fallback})
const Registration = loadable(() => import('./pages/registration'), {
fallback
})
const ResetPassword = loadable(() => import('./pages/reset-password'), {fallback})
const Account = loadable(() => import('./pages/account'), {fallback})
const LoginRedirect = loadable(() => import('./pages/login-redirect'), {fallback})
const ProductDetail = loadable(() => import('./pages/product-detail'), {fallback})
const ProductList = loadable(() => import('./pages/product-list'), {
fallback
})
const StoreLocator = loadable(() => import('./pages/store-locator'), {
fallback
})
const Wishlist = loadable(() => import('./pages/account/wishlist'), {
fallback
})
const PageNotFound = loadable(() => import('./pages/page-not-found'))
export const routes = [
{
path: '/',
component: Home,
exact: true
},
{
path: '/home',
component: Home,
exact: true
},
{
path: '/login',
component: Login,
exact: true
},
{
path: '/registration',
component: Registration,
exact: true
},
{
path: '/reset-password',
component: ResetPassword,
exact: true
},
{
path: '/account',
component: Account
},
{
path: '/callback',
component: LoginRedirect,
exact: true
},
{
path: '/product/:productId',
component: ProductDetail
},
{
path: '/search',
component: ProductList
},
{
path: '/category/:categoryId',
component: ProductList
},
{
path: '/account/wishlist',
component: Wishlist
},
{
path: '/store-locator',
component: StoreLocator
},
{
path: '*',
component: withRouter((props) => {
const {location} = props
const urlParams = new URLSearchParams(location.search)
useEffect(() => {
const newURL = new URL(window.location)
if (!urlParams.has('redirected')) {
newURL.searchParams.append('redirected', '1')
window.location.href = newURL
}
}, [window.location.href])
if (urlParams.has('redirected')) {
return <PageNotFound {...props} />
}
return null
})
}
]
export default () => {
const config = getConfig()
return configureRoutes(routes, config, {
ignoredRoutes: ['/callback', '*']
})
}