From 744cf1aef6789443a669f9f2a6ce73b43ac3c2cf Mon Sep 17 00:00:00 2001 From: Markus <1720843+maxmarkus@users.noreply.github.com> Date: Thu, 21 Nov 2019 14:51:49 +0100 Subject: [PATCH] Bugfix invalid initial root navnode (#979) --- core/src/utilities/helpers/routing-helpers.js | 12 ++++++++- docs/navigation-parameters-reference.md | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/core/src/utilities/helpers/routing-helpers.js b/core/src/utilities/helpers/routing-helpers.js index 836c46a516..390ee12b38 100644 --- a/core/src/utilities/helpers/routing-helpers.js +++ b/core/src/utilities/helpers/routing-helpers.js @@ -30,7 +30,17 @@ class RoutingHelpersClass { return lastElement.defaultChildNode; } else if (children && children.length) { const rootPath = pathData.navigationPath.length === 1; - if (rootPath) return children[0].pathSegment; + if (rootPath) { + const firstNodeWithPathSegment = children.find( + child => child.pathSegment + ); + return ( + (firstNodeWithPathSegment && firstNodeWithPathSegment.pathSegment) || + console.error( + 'At least one navigation node in the root hierarchy must have a pathSegment.' + ) + ); + } const validChild = children.find( child => child.pathSegment && diff --git a/docs/navigation-parameters-reference.md b/docs/navigation-parameters-reference.md index b1765a780f..07e78f221a 100644 --- a/docs/navigation-parameters-reference.md +++ b/docs/navigation-parameters-reference.md @@ -129,6 +129,31 @@ Node parameters are all the parameters that can be added to an individual naviga - **type**: string - **description**: sets the child node that Luigi activates automatically if the current node has no **viewUrl** defined. Provide **pathSegment** of the child node you want to activate as a string. + +>**NOTE:** To define a root-level **defaultChildNode** which is different than the first header navigation node, set an object with **defaultChildNode** and **children** set to `navigation.nodes` instead of an array of nodes. + +- **example**: +```javascript +settings: { + navigation: { + nodes: { + defaultChildNode: 'overview', + children: [ + { + pathSegment: 'docs', + label: 'Documentation', + viewUrl: '...' + }, + { + pathSegment: 'overview', + label: 'Overview', + viewUrl: '...' + } + ] + } + } +``` + ### isolateView - **type**: boolean - **description**: renders the view in a new frame when you enter and leave the node. This setting overrides the same-domain frame re-usage. The **isolateView** is disabled by default.