diff --git a/packages/react-router/package.json b/packages/react-router/package.json index 63ca388286..f862b89089 100644 --- a/packages/react-router/package.json +++ b/packages/react-router/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/react-router", - "version": "4.9.0-rc.2", + "version": "4.10.0-rc.3", "description": "React Router wrapper for @ionic/react", "keywords": [ "ionic", @@ -37,16 +37,16 @@ "tslib": "*" }, "peerDependencies": { - "@ionic/core": "^4.9.0", - "@ionic/react": "4.9.0-rc.2", + "@ionic/core": "^4.10.0", + "@ionic/react": "4.10.0-rc.3", "react": "^16.8.6", "react-dom": "^16.8.6", "react-router": "^5.0.1", "react-router-dom": "^5.0.1" }, "devDependencies": { - "@ionic/core": "^4.9.0", - "@ionic/react": "4.9.0-rc.2", + "@ionic/core": "^4.10.0", + "@ionic/react": "4.10.0-rc.3", "@types/jest": "^23.3.9", "@types/node": "12.6.9", "@types/react": "^16.9.2", diff --git a/packages/react-router/src/ReactRouter/NavManager.tsx b/packages/react-router/src/ReactRouter/NavManager.tsx index faf72a7f4e..ab5f5e0a8c 100644 --- a/packages/react-router/src/ReactRouter/NavManager.tsx +++ b/packages/react-router/src/ReactRouter/NavManager.tsx @@ -4,7 +4,7 @@ import { Location as HistoryLocation, UnregisterCallback } from 'history'; import React from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { StackManager } from './StackManager'; -import { generateUniqueId } from '../utils'; +import { generateId } from '../utils'; import { LocationHistory } from '../utils/LocationHistory' import { ViewItem } from './ViewItem'; import { ViewStack } from './ViewStacks'; @@ -44,7 +44,7 @@ export class NavManager extends React.Component view.show = false; view.ionPageElement = undefined; view.isIonRoute = false; - view.key = generateUniqueId(); + view.prevId = undefined; + view.key = generateId(); this.setState({ viewStacks }); @@ -76,10 +77,6 @@ class RouteManager extends React.Component } leavingView = viewStacks.findViewInfoById(this.activeIonPageId).view; - if (leavingView && leavingView.routeData.match!.url === location.pathname) { - return; - } - if (enteringView) { if (enteringView.isIonRoute) { @@ -96,7 +93,7 @@ class RouteManager extends React.Component * If the page is being pushed into the stack by another view, * record the view that originally directed to the new view for back button purposes. */ - enteringView.prevId = leavingView.id; + enteringView.prevId = enteringView.prevId || leavingView.id; } else { direction = direction || 'back'; leavingView.mount = false; @@ -159,8 +156,8 @@ class RouteManager extends React.Component await this.registerViewStack(id, activeId, views, routerOutlet, this.props.location); function createViewItem(child: React.ReactElement, location: HistoryLocation) { - const viewId = generateUniqueId(); - const key = generateUniqueId(); + const viewId = generateId(); + const key = generateId(); const route = child; const matchProps = { exact: child.props.exact, @@ -182,7 +179,7 @@ class RouteManager extends React.Component }; if (!!match && view.isIonRoute) { activeId = viewId; - }; + } return view; } } diff --git a/packages/react-router/src/ReactRouter/StackManager.tsx b/packages/react-router/src/ReactRouter/StackManager.tsx index b458525b6f..ab7a4b5877 100644 --- a/packages/react-router/src/ReactRouter/StackManager.tsx +++ b/packages/react-router/src/ReactRouter/StackManager.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { generateUniqueId, isDevMode } from '../utils'; +import { generateId, isDevMode } from '../utils'; import { View } from './View'; import { ViewTransitionManager } from './ViewTransitionManager'; import { RouteManagerContext } from './RouteManagerContext'; @@ -18,7 +18,7 @@ export class StackManager extends React.Component { }; export const deprecationWarning = (message: string) => { - if(isDevMode()) { + if (isDevMode()) { console.warn(message); } }; diff --git a/packages/react-router/src/utils/generateId.ts b/packages/react-router/src/utils/generateId.ts new file mode 100644 index 0000000000..120d724cc3 --- /dev/null +++ b/packages/react-router/src/utils/generateId.ts @@ -0,0 +1,3 @@ +let count = 0; + +export const generateId = () => (count++).toString(); diff --git a/packages/react-router/src/utils/generateUniqueId.ts b/packages/react-router/src/utils/generateUniqueId.ts deleted file mode 100644 index 2106a4d1b4..0000000000 --- a/packages/react-router/src/utils/generateUniqueId.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const generateUniqueId = (length: number = 10) => { - const charPool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; - const charArray: string[] = []; - for(let i = 0; i < length; i++) { - charArray.push(charPool[Math.floor(Math.random() * charPool.length)]); - } - return charArray.join(''); -}; diff --git a/packages/react-router/src/utils/index.ts b/packages/react-router/src/utils/index.ts index 2e764e3222..5c9612f496 100644 --- a/packages/react-router/src/utils/index.ts +++ b/packages/react-router/src/utils/index.ts @@ -1,2 +1,2 @@ -export * from './generateUniqueId'; +export * from './generateId'; export * from './dev'; diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 4ab7b8e269..dff36a8365 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,19 @@ +# [4.10.0-rc3] -# [4.8.0-rc2] +## Bug fixes + +Pages should maintain their original previous page id [2afcb6](https://github.com/ionic-team/ionic/commit/2afcb6c80b167b95beb79641504d9237b498dbef), fixes [#19351](https://github.com/ionic-team/ionic/issues/19351) + +Dismiss overlay component on unmount, [3c2694](https://github.com/ionic-team/ionic/commit/3c26946d47b37d42dfaa3294cfb6bf8f0ef11aa4), fixes [#19377](https://github.com/ionic-team/ionic/issues/19377) + +Render first route even if url is same, fixes [#19392](https://github.com/ionic-team/ionic/issues/19392) + +## Breaking Changes + +### Components with href attributes and the new routerLink prop +As of RC3, components that use the href prop (`IonButton`, `IonItem`, etc..), no longer run these links through the router. As a result, page transitions are no longer applied to these links. To maintain page transitions, use the new `routerLink` prop instead. The href prop should be used when you want to enforce a full browser transition on the page, or when you need to link to an external resource. + +# [4.9.0-rc2] ## Features diff --git a/packages/react/package.json b/packages/react/package.json index 8bc0da4444..1b5abb01b5 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/react", - "version": "4.9.0-rc.2", + "version": "4.10.0-rc.3", "description": "React specific wrapper for @ionic/core", "keywords": [ "ionic", @@ -38,7 +38,7 @@ "css/" ], "dependencies": { - "@ionic/core": "^4.9.0", + "@ionic/core": "^4.10.0", "tslib": "*" }, "peerDependencies": { diff --git a/packages/react/src/components/createComponent.tsx b/packages/react/src/components/createComponent.tsx index 4237caa88f..6a1d315320 100644 --- a/packages/react/src/components/createComponent.tsx +++ b/packages/react/src/components/createComponent.tsx @@ -6,11 +6,13 @@ import { NavContext } from '../contexts/NavContext'; import { ReactProps } from './ReactProps'; import { RouterDirection } from './hrefprops'; import { attachEventProps, createForwardRef, dashToPascalCase, isCoveredByReact } from './utils'; +import { deprecationWarning } from './utils/dev'; interface IonicReactInternalProps { forwardedRef?: React.Ref; children?: React.ReactNode; href?: string; + routerLink?: string; target?: string; style?: string; ref?: React.Ref; @@ -32,6 +34,11 @@ export const createReactComponent = ( componentDidMount() { this.componentDidUpdate(this.props); + if (this.props.href) { + setTimeout(() => { + deprecationWarning('hrefchange', 'As of RC3, href links no longer go through the router, so transitions will not be applied to these links. To maintain transitions, use the new routerLink prop.'); + }, 2000); + } } componentDidUpdate(prevProps: IonicReactInternalProps) { @@ -40,11 +47,10 @@ export const createReactComponent = ( } private handleClick = (e: MouseEvent) => { - // TODO: review target usage - const { href, routerDirection } = this.props; - if (href !== undefined && this.context.hasIonicRouter()) { + const { routerLink, routerDirection } = this.props; + if (routerLink !== undefined) { e.preventDefault(); - this.context.navigate(href, routerDirection); + this.context.navigate(routerLink, routerDirection); } } diff --git a/packages/react/src/components/createControllerComponent.tsx b/packages/react/src/components/createControllerComponent.tsx index 786d37e630..bdc9e1c2cb 100644 --- a/packages/react/src/components/createControllerComponent.tsx +++ b/packages/react/src/components/createControllerComponent.tsx @@ -34,12 +34,15 @@ export const createControllerComponent = = Omit & { + routerLink?: string; routerDirection?: RouterDirection; }; diff --git a/packages/react/src/components/utils/dev.ts b/packages/react/src/components/utils/dev.ts new file mode 100644 index 0000000000..cc6f9ed081 --- /dev/null +++ b/packages/react/src/components/utils/dev.ts @@ -0,0 +1,14 @@ +export const isDevMode = () => { + return process && process.env && process.env.NODE_ENV === 'development'; +}; + +const warnings: { [key: string]: boolean } = {}; + +export const deprecationWarning = (key: string, message: string) => { + if (isDevMode()) { + if (!warnings[key]) { + console.warn(message); + warnings[key] = true; + } + } +};