Skip to content

Commit

Permalink
Default child node mechanism breaks if path ends with a slash (SAP#283)
Browse files Browse the repository at this point in the history
Fix for default child node mechanism breaks if path ends with a slash
  • Loading branch information
pekura authored and kwiatekus committed Dec 11, 2018
1 parent 58f4f49 commit 6ac692e
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions core/src/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
containsAllSegments,
isIE,
getConfigValueFromObject,
addLeadingSlash
addLeadingSlash,
trimTrailingSlash
} from '../utilities/helpers';
import { getConfigValueFromObjectAsync } from '../utilities/async-helpers';

Expand Down Expand Up @@ -330,10 +331,11 @@ export const handleRouteChange = async (path, component, node, config) => {
return;
}
try {
const pathUrl = path && path.length ? getPathWithoutHash(path) : '';
const pathUrlRaw = path && path.length ? getPathWithoutHash(path) : '';
const pathUrl = trimTrailingSlash(pathUrlRaw.split('?')[0]);
const pathData = await getNavigationPath(
LuigiConfig.getConfigValueAsync('navigation.nodes'),
pathUrl.split('?')[0]
pathUrl
);

const hideNav = LuigiConfig.getConfigBooleanValue(
Expand All @@ -345,21 +347,21 @@ export const handleRouteChange = async (path, component, node, config) => {
isolateView = false,
hideSideNav = false
} = getLastNodeObject(pathData);
const params = parseParams(pathUrl.split('?')[1]);
const params = parseParams(pathUrlRaw.split('?')[1]);
const nodeParams = getNodeParams(params);
const pathParams = getPathParams(pathData.navigationPath);
const viewGroup = findViewGroup(getLastNodeObject(pathData));

if (!viewUrl) {
const routeExists = isExistingRoute(path, pathData);
const routeExists = isExistingRoute(pathUrl, pathData);

if (routeExists) {
const defaultChildNode = await getDefaultChildNode(pathData);
navigateTo(`${pathUrl ? `/${pathUrl}` : ''}/${defaultChildNode}`);
} else {
const alert = {
message: 'Could not find the requested route',
link: pathUrl
link: pathUrlRaw
};

component.set({ alert });
Expand All @@ -370,11 +372,11 @@ export const handleRouteChange = async (path, component, node, config) => {
}

if (!containsAllSegments(pathUrl, pathData.navigationPath)) {
const matchedPath = await matchPath(pathUrl);
const matchedPath = await matchPath(pathUrlRaw);

const alert = {
message: 'Could not map the exact target node for the requested route',
link: pathUrl
link: pathUrlRaw
};

component.set({ alert });
Expand Down Expand Up @@ -440,7 +442,7 @@ export const matchPath = async path => {
const pathUrl = 0 < path.length ? getPathWithoutHash(path) : path;
const pathData = await getNavigationPath(
LuigiConfig.getConfigValueAsync('navigation.nodes'),
pathUrl.split('?')[0]
trimTrailingSlash(pathUrl.split('?')[0])
);
if (pathData.navigationPath.length > 0) {
const lastNode =
Expand Down

0 comments on commit 6ac692e

Please sign in to comment.