From e729610dc86b92bc1a5c8f9c46eeca673b12c7e7 Mon Sep 17 00:00:00 2001 From: "Manu Mtz.-Almeida" Date: Tue, 13 Mar 2018 23:40:16 +0100 Subject: [PATCH] fix(router): rename API to match stencil-router --- core/src/components.d.ts | 4 ++-- core/src/components/route/readme.md | 12 ++++++------ core/src/components/route/route.tsx | 4 ++-- core/src/components/router/test/basic/index.html | 12 ++++++------ core/src/components/router/test/parser.spec.tsx | 2 +- core/src/components/router/utils/parser.ts | 10 +++------- 6 files changed, 20 insertions(+), 24 deletions(-) diff --git a/core/src/components.d.ts b/core/src/components.d.ts index b0d1d41367..405b3a1215 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -2601,9 +2601,9 @@ declare global { namespace JSXElements { export interface IonRouteAttributes extends HTMLAttributes { component?: string; - params?: {[key: string]: any}; - path?: string; + componentProps?: {[key: string]: any}; redirectTo?: string; + url?: string; } } } diff --git a/core/src/components/route/readme.md b/core/src/components/route/readme.md index 24fcd82c4e..811bba7e2a 100644 --- a/core/src/components/route/readme.md +++ b/core/src/components/route/readme.md @@ -12,17 +12,17 @@ string -#### params +#### componentProps -#### path +#### redirectTo string -#### redirectTo +#### url string @@ -34,17 +34,17 @@ string string -#### params +#### component-props -#### path +#### redirect-to string -#### redirect-to +#### url string diff --git a/core/src/components/route/route.tsx b/core/src/components/route/route.tsx index c59464ed8c..8eaaa3220c 100644 --- a/core/src/components/route/route.tsx +++ b/core/src/components/route/route.tsx @@ -5,8 +5,8 @@ import { Component, Prop } from '@stencil/core'; tag: 'ion-route' }) export class Route { - @Prop() path = ''; + @Prop() url = ''; @Prop() component: string; @Prop() redirectTo: string; - @Prop() params: {[key: string]: any}; + @Prop() componentProps: {[key: string]: any}; } diff --git a/core/src/components/router/test/basic/index.html b/core/src/components/router/test/basic/index.html index 0fc2cde6d7..1210cebb8a 100644 --- a/core/src/components/router/test/basic/index.html +++ b/core/src/components/router/test/basic/index.html @@ -106,16 +106,16 @@ - + - + - - + + - - + + diff --git a/core/src/components/router/test/parser.spec.tsx b/core/src/components/router/test/parser.spec.tsx index c8ab9938dc..5615effe6d 100644 --- a/core/src/components/router/test/parser.spec.tsx +++ b/core/src/components/router/test/parser.spec.tsx @@ -60,7 +60,7 @@ describe('flattenRouterTree', () => { export function mockRouteElement(path: string, component: string) { const el = mockElement('ion-route'); - el.setAttribute('path', path); + el.setAttribute('url', path); (el as any).component = component; return el; } diff --git a/core/src/components/router/utils/parser.ts b/core/src/components/router/utils/parser.ts index 16d6012706..ddbbc073e9 100644 --- a/core/src/components/router/utils/parser.ts +++ b/core/src/components/router/utils/parser.ts @@ -10,7 +10,7 @@ export function readRedirects(root: Element): RouteRedirect[] { throw new Error('Can\'t mix the component and redirectTo attribute in the same ion-route'); } return { - path: parsePath(readProp(el, 'path')), + path: parsePath(readProp(el, 'url')), to: parsePath(readProp(el, 'redirectTo')) }; }); @@ -20,14 +20,10 @@ export function readRoutes(root: Element): RouteTree { return (Array.from(root.children) as HTMLIonRouteElement[]) .filter(el => el.tagName === 'ION-ROUTE' && el.component) .map(el => { - const path = parsePath(readProp(el, 'path')); - if (path.includes(':id')) { - console.warn('Using ":id" is not recommended in `ion-route`, it causes conflicts in the DOM'); - } return { - path: path, + path: parsePath(readProp(el, 'url')), id: readProp(el, 'component').toLowerCase(), - params: el.params, + params: el.componentProps, children: readRoutes(el) }; });