mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 10:01:59 +08:00
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ionic/react-router",
|
"name": "@ionic/react-router",
|
||||||
"version": "4.9.0-rc.2",
|
"version": "4.10.0-rc.3",
|
||||||
"description": "React Router wrapper for @ionic/react",
|
"description": "React Router wrapper for @ionic/react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"ionic",
|
"ionic",
|
||||||
@ -37,16 +37,16 @@
|
|||||||
"tslib": "*"
|
"tslib": "*"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ionic/core": "^4.9.0",
|
"@ionic/core": "^4.10.0",
|
||||||
"@ionic/react": "4.9.0-rc.2",
|
"@ionic/react": "4.10.0-rc.3",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.8.6",
|
"react-dom": "^16.8.6",
|
||||||
"react-router": "^5.0.1",
|
"react-router": "^5.0.1",
|
||||||
"react-router-dom": "^5.0.1"
|
"react-router-dom": "^5.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ionic/core": "^4.9.0",
|
"@ionic/core": "^4.10.0",
|
||||||
"@ionic/react": "4.9.0-rc.2",
|
"@ionic/react": "4.10.0-rc.3",
|
||||||
"@types/jest": "^23.3.9",
|
"@types/jest": "^23.3.9",
|
||||||
"@types/node": "12.6.9",
|
"@types/node": "12.6.9",
|
||||||
"@types/react": "^16.9.2",
|
"@types/react": "^16.9.2",
|
||||||
|
@ -4,7 +4,7 @@ import { Location as HistoryLocation, UnregisterCallback } from 'history';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RouteComponentProps } from 'react-router-dom';
|
import { RouteComponentProps } from 'react-router-dom';
|
||||||
import { StackManager } from './StackManager';
|
import { StackManager } from './StackManager';
|
||||||
import { generateUniqueId } from '../utils';
|
import { generateId } from '../utils';
|
||||||
import { LocationHistory } from '../utils/LocationHistory'
|
import { LocationHistory } from '../utils/LocationHistory'
|
||||||
import { ViewItem } from './ViewItem';
|
import { ViewItem } from './ViewItem';
|
||||||
import { ViewStack } from './ViewStacks';
|
import { ViewStack } from './ViewStacks';
|
||||||
@ -44,7 +44,7 @@ export class NavManager extends React.Component<NavManagerProps, NavManagerState
|
|||||||
|
|
||||||
this.locationHistory.add({
|
this.locationHistory.add({
|
||||||
hash: window.location.hash,
|
hash: window.location.hash,
|
||||||
key: generateUniqueId(6),
|
key: generateId(),
|
||||||
pathname: window.location.pathname,
|
pathname: window.location.pathname,
|
||||||
search: window.location.search,
|
search: window.location.search,
|
||||||
state: {}
|
state: {}
|
||||||
|
@ -3,7 +3,7 @@ import { RouterDirection } from '@ionic/react';
|
|||||||
import { Action as HistoryAction, Location as HistoryLocation, UnregisterCallback } from 'history';
|
import { Action as HistoryAction, Location as HistoryLocation, UnregisterCallback } from 'history';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BrowserRouter, BrowserRouterProps, matchPath, RouteComponentProps, withRouter } from 'react-router-dom';
|
import { BrowserRouter, BrowserRouterProps, matchPath, RouteComponentProps, withRouter } from 'react-router-dom';
|
||||||
import { generateUniqueId } from '../utils';
|
import { generateId } from '../utils';
|
||||||
import { IonRouteData } from './IonRouteData';
|
import { IonRouteData } from './IonRouteData';
|
||||||
import { NavManager } from './NavManager';
|
import { NavManager } from './NavManager';
|
||||||
import { RouteManagerContext, RouteManagerContextState } from './RouteManagerContext';
|
import { RouteManagerContext, RouteManagerContextState } from './RouteManagerContext';
|
||||||
@ -49,7 +49,8 @@ class RouteManager extends React.Component<RouteManagerProps, RouteManagerState>
|
|||||||
view.show = false;
|
view.show = false;
|
||||||
view.ionPageElement = undefined;
|
view.ionPageElement = undefined;
|
||||||
view.isIonRoute = false;
|
view.isIonRoute = false;
|
||||||
view.key = generateUniqueId();
|
view.prevId = undefined;
|
||||||
|
view.key = generateId();
|
||||||
this.setState({
|
this.setState({
|
||||||
viewStacks
|
viewStacks
|
||||||
});
|
});
|
||||||
@ -76,10 +77,6 @@ class RouteManager extends React.Component<RouteManagerProps, RouteManagerState>
|
|||||||
}
|
}
|
||||||
leavingView = viewStacks.findViewInfoById(this.activeIonPageId).view;
|
leavingView = viewStacks.findViewInfoById(this.activeIonPageId).view;
|
||||||
|
|
||||||
if (leavingView && leavingView.routeData.match!.url === location.pathname) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enteringView) {
|
if (enteringView) {
|
||||||
|
|
||||||
if (enteringView.isIonRoute) {
|
if (enteringView.isIonRoute) {
|
||||||
@ -96,7 +93,7 @@ class RouteManager extends React.Component<RouteManagerProps, RouteManagerState>
|
|||||||
* If the page is being pushed into the stack by another view,
|
* 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.
|
* 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 {
|
} else {
|
||||||
direction = direction || 'back';
|
direction = direction || 'back';
|
||||||
leavingView.mount = false;
|
leavingView.mount = false;
|
||||||
@ -159,8 +156,8 @@ class RouteManager extends React.Component<RouteManagerProps, RouteManagerState>
|
|||||||
await this.registerViewStack(id, activeId, views, routerOutlet, this.props.location);
|
await this.registerViewStack(id, activeId, views, routerOutlet, this.props.location);
|
||||||
|
|
||||||
function createViewItem(child: React.ReactElement<any>, location: HistoryLocation) {
|
function createViewItem(child: React.ReactElement<any>, location: HistoryLocation) {
|
||||||
const viewId = generateUniqueId();
|
const viewId = generateId();
|
||||||
const key = generateUniqueId();
|
const key = generateId();
|
||||||
const route = child;
|
const route = child;
|
||||||
const matchProps = {
|
const matchProps = {
|
||||||
exact: child.props.exact,
|
exact: child.props.exact,
|
||||||
@ -182,7 +179,7 @@ class RouteManager extends React.Component<RouteManagerProps, RouteManagerState>
|
|||||||
};
|
};
|
||||||
if (!!match && view.isIonRoute) {
|
if (!!match && view.isIonRoute) {
|
||||||
activeId = viewId;
|
activeId = viewId;
|
||||||
};
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { generateUniqueId, isDevMode } from '../utils';
|
import { generateId, isDevMode } from '../utils';
|
||||||
import { View } from './View';
|
import { View } from './View';
|
||||||
import { ViewTransitionManager } from './ViewTransitionManager';
|
import { ViewTransitionManager } from './ViewTransitionManager';
|
||||||
import { RouteManagerContext } from './RouteManagerContext';
|
import { RouteManagerContext } from './RouteManagerContext';
|
||||||
@ -18,7 +18,7 @@ export class StackManager extends React.Component<StackManagerProps, StackManage
|
|||||||
|
|
||||||
constructor(props: StackManagerProps) {
|
constructor(props: StackManagerProps) {
|
||||||
super(props);
|
super(props);
|
||||||
this.id = this.props.id || generateUniqueId();
|
this.id = this.props.id || generateId();
|
||||||
this.handleViewSync = this.handleViewSync.bind(this);
|
this.handleViewSync = this.handleViewSync.bind(this);
|
||||||
this.handleHideView = this.handleHideView.bind(this);
|
this.handleHideView = this.handleHideView.bind(this);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ export const isDevMode = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const deprecationWarning = (message: string) => {
|
export const deprecationWarning = (message: string) => {
|
||||||
if(isDevMode()) {
|
if (isDevMode()) {
|
||||||
console.warn(message);
|
console.warn(message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
3
packages/react-router/src/utils/generateId.ts
Normal file
3
packages/react-router/src/utils/generateId.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
let count = 0;
|
||||||
|
|
||||||
|
export const generateId = () => (count++).toString();
|
@ -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('');
|
|
||||||
};
|
|
@ -1,2 +1,2 @@
|
|||||||
export * from './generateUniqueId';
|
export * from './generateId';
|
||||||
export * from './dev';
|
export * from './dev';
|
||||||
|
@ -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
|
## Features
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ionic/react",
|
"name": "@ionic/react",
|
||||||
"version": "4.9.0-rc.2",
|
"version": "4.10.0-rc.3",
|
||||||
"description": "React specific wrapper for @ionic/core",
|
"description": "React specific wrapper for @ionic/core",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"ionic",
|
"ionic",
|
||||||
@ -38,7 +38,7 @@
|
|||||||
"css/"
|
"css/"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ionic/core": "^4.9.0",
|
"@ionic/core": "^4.10.0",
|
||||||
"tslib": "*"
|
"tslib": "*"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
@ -6,11 +6,13 @@ import { NavContext } from '../contexts/NavContext';
|
|||||||
import { ReactProps } from './ReactProps';
|
import { ReactProps } from './ReactProps';
|
||||||
import { RouterDirection } from './hrefprops';
|
import { RouterDirection } from './hrefprops';
|
||||||
import { attachEventProps, createForwardRef, dashToPascalCase, isCoveredByReact } from './utils';
|
import { attachEventProps, createForwardRef, dashToPascalCase, isCoveredByReact } from './utils';
|
||||||
|
import { deprecationWarning } from './utils/dev';
|
||||||
|
|
||||||
interface IonicReactInternalProps<ElementType> {
|
interface IonicReactInternalProps<ElementType> {
|
||||||
forwardedRef?: React.Ref<ElementType>;
|
forwardedRef?: React.Ref<ElementType>;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
href?: string;
|
href?: string;
|
||||||
|
routerLink?: string;
|
||||||
target?: string;
|
target?: string;
|
||||||
style?: string;
|
style?: string;
|
||||||
ref?: React.Ref<any>;
|
ref?: React.Ref<any>;
|
||||||
@ -32,6 +34,11 @@ export const createReactComponent = <PropType, ElementType>(
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.componentDidUpdate(this.props);
|
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<ElementType>) {
|
componentDidUpdate(prevProps: IonicReactInternalProps<ElementType>) {
|
||||||
@ -40,11 +47,10 @@ export const createReactComponent = <PropType, ElementType>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleClick = (e: MouseEvent) => {
|
private handleClick = (e: MouseEvent) => {
|
||||||
// TODO: review target usage
|
const { routerLink, routerDirection } = this.props;
|
||||||
const { href, routerDirection } = this.props;
|
if (routerLink !== undefined) {
|
||||||
if (href !== undefined && this.context.hasIonicRouter()) {
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.context.navigate(href, routerDirection);
|
this.context.navigate(routerLink, routerDirection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,12 +34,15 @@ export const createControllerComponent = <OptionsType extends object, OverlayTyp
|
|||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const { isOpen } = this.props;
|
const { isOpen } = this.props;
|
||||||
// TODO
|
|
||||||
if (isOpen as boolean) {
|
if (isOpen as boolean) {
|
||||||
this.present();
|
this.present();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
if (this.overlay) { this.overlay.dismiss(); }
|
||||||
|
}
|
||||||
|
|
||||||
async componentDidUpdate(prevProps: Props) {
|
async componentDidUpdate(prevProps: Props) {
|
||||||
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
||||||
this.present(prevProps);
|
this.present(prevProps);
|
||||||
|
@ -37,14 +37,16 @@ export const createOverlayComponent = <T extends object, OverlayType extends Ove
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// TODO
|
|
||||||
if (this.props.isOpen as boolean) {
|
if (this.props.isOpen as boolean) {
|
||||||
this.present();
|
this.present();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async componentDidUpdate(prevProps: Props) {
|
componentWillUnmount() {
|
||||||
|
if (this.overlay) { this.overlay.dismiss(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
async componentDidUpdate(prevProps: Props) {
|
||||||
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
|
||||||
this.present(prevProps);
|
this.present(prevProps);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
export declare type RouterDirection = 'forward' | 'back' | 'none';
|
export declare type RouterDirection = 'forward' | 'back' | 'none';
|
||||||
|
|
||||||
export type HrefProps<T> = Omit<T, 'routerDirection'> & {
|
export type HrefProps<T> = Omit<T, 'routerDirection'> & {
|
||||||
|
routerLink?: string;
|
||||||
routerDirection?: RouterDirection;
|
routerDirection?: RouterDirection;
|
||||||
};
|
};
|
||||||
|
14
packages/react/src/components/utils/dev.ts
Normal file
14
packages/react/src/components/utils/dev.ts
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Reference in New Issue
Block a user