Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function (
currentCard: Card,
nextCard: Card,
currentRouterHistory: RouterHistory,
nextRouterHistory: RouterHistory,
): boolean {
const { location: currentLocation } = currentRouterHistory
const { entries, index, location: nextLocation } = nextRouterHistory
if (entries === undefined || index === undefined) return false
// Get entries and matchers
const previousEntry = entries[index - 1]
const currentEntry = entries[index]
const nextEntry = entries[index + 1]
const matchCurrentRoute = matchPath(nextLocation.pathname, currentCard.path, currentCard)
const matchNextRoute = matchPath(nextLocation.pathname, nextCard.path, nextCard)
return (
// Test if pathame are different
(currentLocation.pathname !== nextLocation.pathname) &&
// case 1) basic pathname
((currentCard.path !== nextCard.path) ||
// case 2) Pathname with query params
// ex: with same path article/:id,
// pathname article/2 !== article/3
(matchCurrentRoute !== null && matchNextRoute !== null &&
Object.keys(matchCurrentRoute.params).length !== 0 &&
Object.keys(matchNextRoute.params).length !== 0 &&
((previousEntry && currentEntry.pathname !== previousEntry.pathname) ||
(nextEntry && currentEntry.pathname !== nextEntry.pathname))
))
)
loadRemoteUserData() {
const {dispatch} = this.props;
const match = matchPath(this.props.location.pathname, {
path: '/@:username',
});
if(match && match.params.username) {
dispatch(getRemoteUserData(match.params.username));
} else {
dispatch(getRemoteUserData(Cookies.get('username')));
}
}
function getContext(pathname: string): ContextState {
let matchResult = matchPath(pathname, {
path: `/:username([^_][^/]+)/:spacename([^_][^/]+|${NO_SPACE_PATH})/:subPath(.*)?`,
exact: false,
strict: false,
});
if (!matchResult) {
matchResult = matchPath(pathname, {
path: '/:username([^_][^/]+)/:subPath(.*)?',
exact: false,
strict: false,
});
}
const username = matchResult ? matchResult.params.username : undefined;
const spacename =
matchResult && matchResult.params.spacename !== NO_SPACE_PATH
? matchResult.params.spacename
: undefined;
const subPath = matchResult
? matchResult.params.subPath
? `/${matchResult.params.subPath}`
: undefined
: pathname;
Object.keys(pathToView).forEach(url => {
const match = matchPath(pathname, url);
if (match) {
const [moduleName, viewName] = pathToView[url];
if (!views[moduleName]) {
views[moduleName] = {[viewName]: 1};
} else {
views[moduleName][viewName] = 1;
}
if (match.params) {
pathData[moduleName] = match.params;
}
}
});
return {views, pathData};
function match(pathname: string, path: string) {
return matchPath(pathname, {path, exact: true})
}
foundPaths = Router.routes.filter((pathObject) => matchPath("/not-found", {
path: pathObject.route,
exact: true
}));
}
const isActive = (path, history) => {
return matchPath(path, {
path: history.location.pathname,
exact: true,
strict: false
})
};
React.Children.forEach(children, (element: any) => {
if (!React.isValidElement(element)) return
const { path: pathProp, exact, strict, sensitive, from } = element.props
const path = pathProp || from
if (match == null) {
child =
element.key != null ? element : React.cloneElement(element, { key })
match = path
? matchPath(location.pathname, { path, exact, strict, sensitive })
: _match
}
key++
})
const getIsPathExcluded = (path) => matchPath(pathSection, { path, exact: true, strict: false });
if (excludePaths && excludePaths.some(getIsPathExcluded)) {
return state => {
const { pathname } = getLocation(state) || {};
if (pathname === lastPathname) {
return lastMatch;
}
lastPathname = pathname;
const match = matchPath(pathname, path);
if (!match || !lastMatch || match.url !== lastMatch.url) {
lastMatch = match;
}
return lastMatch;
};
};