(routePath)
| 62 | // RoutePaths do not have query params, basePaths, and should |
| 63 | // resemble the same string as passed in the static.config.js routes |
| 64 | export function getRoutePath(routePath) { |
| 65 | // Detect falsey paths and the root path |
| 66 | if ( |
| 67 | !routePath || |
| 68 | routePath === '/' || |
| 69 | routePath === process.env.REACT_STATIC_BASE_PATH |
| 70 | ) { |
| 71 | return '/' |
| 72 | } |
| 73 | |
| 74 | // Remove origin, hashes, and query params |
| 75 | if (typeof document !== 'undefined') { |
| 76 | routePath = routePath.replace(window.location.origin, '') |
| 77 | routePath = routePath.replace(/#.*/, '') |
| 78 | routePath = routePath.replace(/\?.*/, '') |
| 79 | } |
| 80 | |
| 81 | // Be sure to remove the base path |
| 82 | if (process.env.REACT_STATIC_BASE_PATH) { |
| 83 | routePath = routePath.replace( |
| 84 | new RegExp(`^\\/?${process.env.REACT_STATIC_BASE_PATH}(\\/|$)`), |
| 85 | '' |
| 86 | ) |
| 87 | } |
| 88 | routePath = routePath || '/' |
| 89 | return pathJoin(routePath) |
| 90 | } |
| 91 | |
| 92 | export function getCurrentRoutePath() { |
| 93 | // If in the browser, use the window |
no test coverage detected
searching dependent graphs…