fix(settings routing): handle trailing slashes in base paths (#10055)
Adjusted URL construction to properly handle trailing slashes in base paths, ensuring consistent matching logic. Added logic for setting the hotkey scope when navigating to the domain settings path.
This commit is contained in:
@ -1,19 +1,32 @@
|
||||
import { useCallback } from 'react';
|
||||
import { matchPath, useLocation } from 'react-router-dom';
|
||||
|
||||
import { AppBasePath } from '@/types/AppBasePath';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
|
||||
export const useIsMatchingLocation = () => {
|
||||
const location = useLocation();
|
||||
|
||||
return useCallback(
|
||||
(path: string, basePath?: AppBasePath) => {
|
||||
const constructedPath = basePath
|
||||
? (new URL(basePath + path, document.location.origin).pathname ?? '')
|
||||
: path;
|
||||
const addTrailingSlash = (path: string) =>
|
||||
path.endsWith('/') ? path : path + '/';
|
||||
|
||||
return !!matchPath(constructedPath, location.pathname);
|
||||
},
|
||||
[location.pathname],
|
||||
);
|
||||
const getConstructedPath = (path: string, basePath?: AppBasePath) => {
|
||||
if (!isNonEmptyString(basePath)) return path;
|
||||
|
||||
return addTrailingSlash(basePath) + path;
|
||||
};
|
||||
|
||||
const isMatchingLocation = (path: string, basePath?: AppBasePath) => {
|
||||
const match = matchPath(
|
||||
getConstructedPath(path, basePath),
|
||||
location.pathname,
|
||||
);
|
||||
const isMatching = isDefined(match);
|
||||
|
||||
return isMatching;
|
||||
};
|
||||
|
||||
return {
|
||||
isMatchingLocation,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user