1212// we don't want it to count toward coverage until we figure out how to cover the `functions`
1313// metric for this file in its test.
1414
15- import React from 'react'
15+ import React , { useEffect } from 'react'
1616import loadable from '@loadable/component'
1717import { getConfig } from '@salesforce/pwa-kit-runtime/utils/ssr-config'
18+ import { withRouter } from 'react-router-dom'
1819
1920// Components
2021import { Skeleton } from '@salesforce/retail-react-app/app/components/shared/ui'
@@ -30,15 +31,6 @@ const Registration = loadable(() => import('./pages/registration'), {
3031} )
3132const ResetPassword = loadable ( ( ) => import ( './pages/reset-password' ) , { fallback} )
3233const Account = loadable ( ( ) => import ( './pages/account' ) , { fallback} )
33- const Cart = loadable ( ( ) => import ( './pages/cart' ) , { fallback} )
34- const Checkout = loadable ( ( ) => import ( './pages/checkout' ) , {
35- fallback
36- } )
37- const CheckoutOneClick = loadable ( ( ) => import ( './pages/checkout-one-click' ) , {
38- fallback
39- } )
40- const CheckoutConfirmation = loadable ( ( ) => import ( './pages/confirmation' ) , { fallback} )
41- const SocialLoginRedirect = loadable ( ( ) => import ( './pages/social-login-redirect' ) , { fallback} )
4234const LoginRedirect = loadable ( ( ) => import ( './pages/login-redirect' ) , { fallback} )
4335const ProductDetail = loadable ( ( ) => import ( './pages/product-detail' ) , { fallback} )
4436const ProductList = loadable ( ( ) => import ( './pages/product-list' ) , {
@@ -58,6 +50,11 @@ export const routes = [
5850 component : Home ,
5951 exact : true
6052 } ,
53+ {
54+ path : '/home' ,
55+ component : Home ,
56+ exact : true
57+ } ,
6158 {
6259 path : '/login' ,
6360 component : Login ,
@@ -77,28 +74,11 @@ export const routes = [
7774 path : '/account' ,
7875 component : Account
7976 } ,
80- {
81- path : '/checkout' ,
82- component : ( props ) => {
83- const enabled = getConfig ( ) ?. app ?. oneClickCheckout ?. enabled
84- return enabled ? < CheckoutOneClick { ...props } /> : < Checkout { ...props } />
85- } ,
86- exact : true
87- } ,
88- {
89- path : '/checkout/confirmation/:orderNo' ,
90- component : CheckoutConfirmation
91- } ,
9277 {
9378 path : '/callback' ,
9479 component : LoginRedirect ,
9580 exact : true
9681 } ,
97- {
98- path : '/cart' ,
99- component : Cart ,
100- exact : true
101- } ,
10282 {
10383 path : '/product/:productId' ,
10484 component : ProductDetail
@@ -118,44 +98,31 @@ export const routes = [
11898 {
11999 path : '/store-locator' ,
120100 component : StoreLocator
101+ } ,
102+ {
103+ path : '*' ,
104+ component : withRouter ( ( props ) => {
105+ const { location} = props
106+ const urlParams = new URLSearchParams ( location . search )
107+
108+ useEffect ( ( ) => {
109+ const newURL = new URL ( window . location )
110+ if ( ! urlParams . has ( 'redirected' ) ) {
111+ newURL . searchParams . append ( 'redirected' , '1' )
112+ window . location . href = newURL
113+ }
114+ } , [ window . location . href ] )
115+ if ( urlParams . has ( 'redirected' ) ) {
116+ return < PageNotFound { ...props } />
117+ }
118+ return null
119+ } )
121120 }
122121]
123122
124123export default ( ) => {
125124 const config = getConfig ( )
126- const loginConfig = config ?. app ?. login
127- const resetPasswordLandingPath = loginConfig ?. resetPassword ?. landingPath
128- const socialLoginEnabled = loginConfig ?. social ?. enabled
129- const socialRedirectURI = loginConfig ?. social ?. redirectURI
130- const passwordlessLoginEnabled = loginConfig ?. passwordless ?. enabled
131- const passwordlessLoginLandingPath = loginConfig ?. passwordless ?. landingPath
132-
133- // Add dynamic routes conditionally (only if features are enabled and paths are defined)
134- const dynamicRoutes = [
135- resetPasswordLandingPath && {
136- path : resetPasswordLandingPath ,
137- component : ResetPassword ,
138- exact : true
139- } ,
140- passwordlessLoginEnabled &&
141- passwordlessLoginLandingPath && {
142- path : passwordlessLoginLandingPath ,
143- component : Login ,
144- exact : true
145- } ,
146- socialLoginEnabled &&
147- socialRedirectURI && {
148- path : socialRedirectURI ,
149- component : SocialLoginRedirect ,
150- exact : true
151- }
152- ] . filter ( Boolean )
153-
154- const allRoutes = configureRoutes ( [ ...routes , ...dynamicRoutes ] , config , {
155- ignoredRoutes : [ '/callback' ] ,
156- fuzzyPathMatching : true
125+ return configureRoutes ( routes , config , {
126+ ignoredRoutes : [ '/callback' , '*' ]
157127 } )
158-
159- // Add catch-all route at the end so it doesn't match before dynamic routes
160- return [ ...allRoutes , { path : '*' , component : PageNotFound } ]
161128}
0 commit comments