-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathroutes.jsx.hbs
More file actions
88 lines (81 loc) · 2.68 KB
/
routes.jsx.hbs
File metadata and controls
88 lines (81 loc) · 2.68 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
/*
* Copyright (c) 2023, 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
*/
{{#if answers.project.hybrid}}
import React, { useEffect } from 'react'
import { withRouter } from 'react-router-dom'
{{else}}
import React from 'react'
{{/if}}
import loadable from '@loadable/component'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
// Components
import {Skeleton} from '{{template.source.name}}/app/components/shared/ui'
import {configureRoutes} from '{{template.source.name}}/app/utils/routes-utils'
import {routes as _routes} from '{{template.source.name}}/app/routes'
const fallback = <Skeleton height="75vh" width="100%" />
// Create your pages here and add them to the routes array
// Use loadable to split code into smaller js chunks
{{#if answers.project.hybrid}}
const Home = loadable(() => import('@salesforce/retail-react-app/app/pages/home'), { fallback })
{{else}}
const Home = loadable(() => import('./pages/home'), {fallback})
{{/if}}
const MyNewRoute = loadable(() => import('./pages/my-new-route'))
{{#if answers.project.hybrid}}
const PageNotFound = loadable(() => import('@salesforce/retail-react-app/app/pages/page-not-found'))
{{/if}}
const routes = [
{
path: '/',
component: Home,
exact: true
},
{{#if answers.project.hybrid}}
{
path: '/home',
component: Home,
exact: true
},
{{/if}}
{
path: '/my-new-route',
component: MyNewRoute
},
{{#if answers.project.hybrid}}
// remove routes from the base template that we want to go to SFRA
..._routes.filter((route) => {
return !(route.path === '/cart' || route.path === '/checkout' || route.path === '*')
}),
{
path: '*',
component: withRouter((props) => {
const { location, history } = 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
}
}, [location.pathname])
if (urlParams.has('redirected')) {
return <PageNotFound {...props} />
}
return null
})
}
{{else}}
..._routes
{{/if}}
]
{{!-- export default routes --}}
export default () => {
const config = getConfig()
return configureRoutes(routes, config, {
ignoredRoutes: ['/callback', '*']
})
}