Skip to content

Commit

Permalink
moving call to removeSiteLocaleFromPath into use-navigation hook
Browse files Browse the repository at this point in the history
  • Loading branch information
sandragolden committed Mar 18, 2023
1 parent 020a8af commit c8a3ff6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* Copyright (c) 2021, salesforce.com, inc.
* Copyright (c) 2023, Salesforce, 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
*/
import {useCallback} from 'react'
import {useHistory} from 'react-router'
import useMultiSite from './use-multi-site'
import {removeSiteLocaleFromPath} from '../utils/url'

/**
* A convenience hook for programmatic navigation uses history's `push` or `replace`. The proper locale
Expand All @@ -26,7 +27,7 @@ const useNavigation = () => {
* @param {...any} args - additional args passed to `.push` or `.replace`
*/
(path, action = 'push', ...args) => {
const updatedHref = buildUrl(path)
const updatedHref = buildUrl(removeSiteLocaleFromPath(path))
history[action](path === '/' ? '/' : updatedHref, ...args)
},
[localeShortCode, site]
Expand Down
4 changes: 2 additions & 2 deletions packages/template-retail-react-app/app/pages/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Seo from '../../components/seo'
import {useForm} from 'react-hook-form'
import {useLocation} from 'react-router-dom'
import useEinstein from '../../commerce-api/hooks/useEinstein'
import {removeSiteLocaleFromPath} from '../../utils/url'

import LoginForm from '../../components/login'

const Login = () => {
Expand Down Expand Up @@ -45,7 +45,7 @@ const Login = () => {
useEffect(() => {
if (customer.authType != null && customer.isRegistered) {
if (location?.state?.directedFrom) {
navigate(removeSiteLocaleFromPath(location.state.directedFrom))
navigate(location.state.directedFrom)
} else {
navigate('/account')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/template-retail-react-app/app/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export const removeQueryParamsFromPath = (path, keys) => {
* removeSiteLocaleFromPath(/RefArch/en-US/account/wishlist)
* // returns '/account/wishlist'
*/
export const removeSiteLocaleFromPath = (pathName) => {
export const removeSiteLocaleFromPath = (pathName = '') => {
let {siteRef, localeRef} = getParamsFromPath(`${pathName}`)

// remove the site alias from the current pathName
Expand Down

0 comments on commit c8a3ff6

Please sign in to comment.