Skip to content

Commit ba06f01

Browse files
fix router
1 parent 72887d1 commit ba06f01

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/src/components/router/utils/parser.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,23 @@ export const readRoutes = (root: Element): RouteChain[] => {
3737
return flattenRouterTree(readRouteNodes(root));
3838
};
3939

40+
/**
41+
* Stencil patches `elm.children` to behave like calling `elm.children` on an
42+
* element with shadow DOM even though the `ion-router` is not a shadow DOM element.
43+
* To allow the `ion-router` to work properly we need to access the original accessor
44+
* for this property which is `__children`.
45+
*/
46+
interface PatchedStencilElement extends Element {
47+
__children?: HTMLCollection;
48+
}
49+
4050
/**
4151
* Reads the route nodes as a tree modeled after the DOM tree of <ion-route> elements.
4252
*
4353
* Note: routes without a component are ignored together with their children.
4454
*/
45-
export const readRouteNodes = (node: Element): RouteTree => {
46-
return (Array.from(node.children) as HTMLIonRouteElement[])
55+
export const readRouteNodes = (node: PatchedStencilElement): RouteTree => {
56+
return (Array.from(node.__children ?? []) as HTMLIonRouteElement[])
4757
.filter((el) => el.tagName === 'ION-ROUTE' && el.component)
4858
.map((el) => {
4959
const component = readProp(el, 'component') as string;

0 commit comments

Comments
 (0)