-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NCL-8833 Remove query string for legacy url rediret
- Loading branch information
Showing
2 changed files
with
29 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { URL_BASE_PATH } from 'common/constants'; | ||
|
||
export const useLegacyUrlRedirector = () => { | ||
useEffect(() => { | ||
const { pathname, hash } = window.location; | ||
const { pathname, hash } = window.location; | ||
|
||
if (pathname.startsWith(URL_BASE_PATH + '/') && hash.startsWith('#/')) { | ||
let newPath = '/' + hash.substring(2); // Remove '#/' and concatenate | ||
if (pathname.startsWith(URL_BASE_PATH + '/') && hash.startsWith('#/')) { | ||
let newPath = '/' + hash.substring(2); // Remove '#/' and concatenate | ||
|
||
// If it contains '/build-configs/', remove everything between '/pnc-web/' and '/build-configs/' | ||
const buildConfigsIndex = newPath.indexOf('/build-configs/'); | ||
if (buildConfigsIndex !== -1) { | ||
newPath = newPath.substring(buildConfigsIndex); | ||
} | ||
console.log( | ||
`You are accessing a legacy PNC URL: ${window.location}. Please save the new URL after redirection for a better experience.` | ||
); | ||
|
||
// If it contains '/builds/', remove everything between '/pnc-web/' and '/builds/' | ||
const buildsIndex = newPath.indexOf('/builds/'); | ||
if (buildsIndex !== -1) { | ||
newPath = newPath.substring(buildsIndex); | ||
} | ||
// Remove the query string part | ||
const queryIndex = newPath.indexOf('?'); | ||
if (queryIndex !== -1) { | ||
const removedQueryString = newPath.substring(queryIndex); | ||
console.log(`Query string removed from old URL: ${removedQueryString}`); | ||
newPath = newPath.substring(0, queryIndex); | ||
} | ||
|
||
console.log(`Redirecting to new URL: ${newPath}`); | ||
window.location.href = URL_BASE_PATH + newPath; | ||
// If it contains '/build-configs/', remove everything between '/pnc-web/' and '/build-configs/' | ||
const buildConfigsIndex = newPath.indexOf('/build-configs/'); | ||
if (buildConfigsIndex !== -1) { | ||
newPath = newPath.substring(buildConfigsIndex); | ||
} | ||
}, []); | ||
|
||
// If it contains '/builds/', remove everything between '/pnc-web/' and '/builds/' | ||
const buildsIndex = newPath.indexOf('/builds/'); | ||
if (buildsIndex !== -1) { | ||
newPath = newPath.substring(buildsIndex); | ||
} | ||
|
||
console.log(`Redirecting to new URL: ${newPath}`); | ||
window.location.href = URL_BASE_PATH + newPath; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters