Fixes https://github.com/twentyhq/core-team-issues/issues/950 This issue was due to the memoization inside `useIsMatchingLocation`, which was rerendered only if the pathname changed but not the search params. After discussion with @lucasbordeau, we decided to remove the hook `useIsMatchingLocation` and to create an equivalent util function which takes the location as an argument. --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
27 lines
704 B
TypeScript
27 lines
704 B
TypeScript
import { Location, matchPath } from 'react-router-dom';
|
|
|
|
import { AppBasePath } from '@/types/AppBasePath';
|
|
import { isNonEmptyString } from '@sniptt/guards';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
const addTrailingSlash = (path: string) =>
|
|
path.endsWith('/') ? path : path + '/';
|
|
|
|
const getConstructedPath = (path: string, basePath?: AppBasePath) => {
|
|
if (!isNonEmptyString(basePath)) return path;
|
|
|
|
return addTrailingSlash(basePath) + path;
|
|
};
|
|
|
|
export const isMatchingLocation = (
|
|
location: Location,
|
|
path: string,
|
|
basePath?: AppBasePath,
|
|
): boolean => {
|
|
const match = matchPath(
|
|
getConstructedPath(path, basePath),
|
|
location.pathname,
|
|
);
|
|
return isDefined(match);
|
|
};
|