@ionic/react-router 7.5.3-dev.11698857666.1220acc8 → 7.5.3-dev.11698858201.14165f23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ReactRouter/IonReactHashRouter.js +37 -0
- package/dist/ReactRouter/IonReactHashRouter.js.map +7 -0
- package/dist/ReactRouter/IonReactMemoryRouter.js +35 -0
- package/dist/ReactRouter/IonReactMemoryRouter.js.map +7 -0
- package/dist/ReactRouter/IonReactRouter.js +37 -0
- package/dist/ReactRouter/IonReactRouter.js.map +7 -0
- package/dist/ReactRouter/IonRouteInner.js +27 -0
- package/dist/ReactRouter/IonRouteInner.js.map +7 -0
- package/dist/ReactRouter/IonRouter.js +250 -0
- package/dist/ReactRouter/IonRouter.js.map +7 -0
- package/dist/ReactRouter/ReactRouterViewStack.js +160 -0
- package/dist/ReactRouter/ReactRouterViewStack.js.map +7 -0
- package/dist/ReactRouter/StackManager.js +270 -0
- package/dist/ReactRouter/StackManager.js.map +7 -0
- package/dist/ReactRouter/clonePageElement.js +21 -0
- package/dist/ReactRouter/clonePageElement.js.map +7 -0
- package/dist/index.js +4 -910
- package/dist/index.js.map +7 -1
- package/package.json +5 -9
- package/dist/types/ReactRouter/IonReactHashRouter.d.ts +0 -23
- package/dist/types/ReactRouter/IonReactMemoryRouter.d.ts +0 -23
- package/dist/types/ReactRouter/IonReactRouter.d.ts +0 -23
- package/dist/types/ReactRouter/IonRouteInner.d.ts +0 -5
- package/dist/types/ReactRouter/IonRouter.d.ts +0 -44
- package/dist/types/ReactRouter/ReactRouterViewStack.d.ts +0 -12
- package/dist/types/ReactRouter/StackManager.d.ts +0 -30
- package/dist/types/ReactRouter/clonePageElement.d.ts +0 -1
- package/dist/types/index.d.ts +0 -3
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { createHashHistory as createHistory } from "history";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Router } from "react-router-dom";
|
|
5
|
+
import { IonRouter } from "./IonRouter";
|
|
6
|
+
export class IonReactHashRouter extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
const { history, ...rest } = props;
|
|
10
|
+
this.history = history || createHistory(rest);
|
|
11
|
+
this.history.listen(this.handleHistoryChange.bind(this));
|
|
12
|
+
this.registerHistoryListener = this.registerHistoryListener.bind(this);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* history@4.x passes separate location and action
|
|
16
|
+
* params. history@5.x passes location and action
|
|
17
|
+
* together as a single object.
|
|
18
|
+
* TODO: If support for React Router <=5 is dropped
|
|
19
|
+
* this logic is no longer needed. We can just assume
|
|
20
|
+
* a single object with both location and action.
|
|
21
|
+
*/
|
|
22
|
+
handleHistoryChange(location, action) {
|
|
23
|
+
const locationValue = location.location || location;
|
|
24
|
+
const actionValue = location.action || action;
|
|
25
|
+
if (this.historyListenHandler) {
|
|
26
|
+
this.historyListenHandler(locationValue, actionValue);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
registerHistoryListener(cb) {
|
|
30
|
+
this.historyListenHandler = cb;
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
const { children, ...props } = this.props;
|
|
34
|
+
return /* @__PURE__ */ React.createElement(Router, { history: this.history, ...props }, /* @__PURE__ */ React.createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=IonReactHashRouter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ReactRouter/IonReactHashRouter.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { Action as HistoryAction, History, Location as HistoryLocation } from 'history';\nimport { createHashHistory as createHistory } from 'history';\nimport React from 'react';\nimport type { BrowserRouterProps } from 'react-router-dom';\nimport { Router } from 'react-router-dom';\n\nimport { IonRouter } from './IonRouter';\n\ninterface IonReactHashRouterProps extends BrowserRouterProps {\n history?: History;\n}\n\nexport class IonReactHashRouter extends React.Component<IonReactHashRouterProps> {\n history: History;\n historyListenHandler?: (location: HistoryLocation, action: HistoryAction) => void;\n\n constructor(props: IonReactHashRouterProps) {\n super(props);\n const { history, ...rest } = props;\n this.history = history || createHistory(rest);\n this.history.listen(this.handleHistoryChange.bind(this));\n this.registerHistoryListener = this.registerHistoryListener.bind(this);\n }\n\n /**\n * history@4.x passes separate location and action\n * params. history@5.x passes location and action\n * together as a single object.\n * TODO: If support for React Router <=5 is dropped\n * this logic is no longer needed. We can just assume\n * a single object with both location and action.\n */\n handleHistoryChange(location: HistoryLocation, action: HistoryAction) {\n const locationValue = (location as any).location || location;\n const actionValue = (location as any).action || action;\n if (this.historyListenHandler) {\n this.historyListenHandler(locationValue, actionValue);\n }\n }\n\n registerHistoryListener(cb: (location: HistoryLocation, action: HistoryAction) => void) {\n this.historyListenHandler = cb;\n }\n\n render() {\n const { children, ...props } = this.props;\n return (\n <Router history={this.history} {...props}>\n <IonRouter registerHistoryListener={this.registerHistoryListener}>{children}</IonRouter>\n </Router>\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,qBAAqB,qBAAqB;AACnD,OAAO,WAAW;AAElB,SAAS,cAAc;AAEvB,SAAS,iBAAiB;AAMnB,aAAM,2BAA2B,MAAM,UAAmC;AAAA,EAI/E,YAAY,OAAgC;AAC1C,UAAM,KAAK;AACX,UAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAC7B,SAAK,UAAU,WAAW,cAAc,IAAI;AAC5C,SAAK,QAAQ,OAAO,KAAK,oBAAoB,KAAK,IAAI,CAAC;AACvD,SAAK,0BAA0B,KAAK,wBAAwB,KAAK,IAAI;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,oBAAoB,UAA2B,QAAuB;AACpE,UAAM,gBAAiB,SAAiB,YAAY;AACpD,UAAM,cAAe,SAAiB,UAAU;AAChD,QAAI,KAAK,sBAAsB;AAC7B,WAAK,qBAAqB,eAAe,WAAW;AAAA,IACtD;AAAA,EACF;AAAA,EAEA,wBAAwB,IAAgE;AACtF,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAU,GAAG,MAAM,IAAI,KAAK;AACpC,WACE,oCAAC,UAAO,SAAS,KAAK,SAAU,GAAG,SACjC,oCAAC,aAAU,yBAAyB,KAAK,2BAA0B,QAAS,CAC9E;AAAA,EAEJ;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Router } from "react-router";
|
|
4
|
+
import { IonRouter } from "./IonRouter";
|
|
5
|
+
export class IonReactMemoryRouter extends React.Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
this.history = props.history;
|
|
9
|
+
this.history.listen(this.handleHistoryChange.bind(this));
|
|
10
|
+
this.registerHistoryListener = this.registerHistoryListener.bind(this);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* history@4.x passes separate location and action
|
|
14
|
+
* params. history@5.x passes location and action
|
|
15
|
+
* together as a single object.
|
|
16
|
+
* TODO: If support for React Router <=5 is dropped
|
|
17
|
+
* this logic is no longer needed. We can just assume
|
|
18
|
+
* a single object with both location and action.
|
|
19
|
+
*/
|
|
20
|
+
handleHistoryChange(location, action) {
|
|
21
|
+
const locationValue = location.location || location;
|
|
22
|
+
const actionValue = location.action || action;
|
|
23
|
+
if (this.historyListenHandler) {
|
|
24
|
+
this.historyListenHandler(locationValue, actionValue);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
registerHistoryListener(cb) {
|
|
28
|
+
this.historyListenHandler = cb;
|
|
29
|
+
}
|
|
30
|
+
render() {
|
|
31
|
+
const { children, ...props } = this.props;
|
|
32
|
+
return /* @__PURE__ */ React.createElement(Router, { ...props }, /* @__PURE__ */ React.createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=IonReactMemoryRouter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ReactRouter/IonReactMemoryRouter.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { Action as HistoryAction, Location as HistoryLocation, MemoryHistory } from 'history';\nimport React from 'react';\nimport type { MemoryRouterProps } from 'react-router';\nimport { Router } from 'react-router';\n\nimport { IonRouter } from './IonRouter';\n\ninterface IonReactMemoryRouterProps extends MemoryRouterProps {\n history: MemoryHistory;\n}\n\nexport class IonReactMemoryRouter extends React.Component<IonReactMemoryRouterProps> {\n history: MemoryHistory;\n historyListenHandler?: (location: HistoryLocation, action: HistoryAction) => void;\n\n constructor(props: IonReactMemoryRouterProps) {\n super(props);\n this.history = props.history;\n this.history.listen(this.handleHistoryChange.bind(this));\n this.registerHistoryListener = this.registerHistoryListener.bind(this);\n }\n\n /**\n * history@4.x passes separate location and action\n * params. history@5.x passes location and action\n * together as a single object.\n * TODO: If support for React Router <=5 is dropped\n * this logic is no longer needed. We can just assume\n * a single object with both location and action.\n */\n handleHistoryChange(location: HistoryLocation, action: HistoryAction) {\n const locationValue = (location as any).location || location;\n const actionValue = (location as any).action || action;\n if (this.historyListenHandler) {\n this.historyListenHandler(locationValue, actionValue);\n }\n }\n\n registerHistoryListener(cb: (location: HistoryLocation, action: HistoryAction) => void) {\n this.historyListenHandler = cb;\n }\n\n render() {\n const { children, ...props } = this.props;\n return (\n <Router {...props}>\n <IonRouter registerHistoryListener={this.registerHistoryListener}>{children}</IonRouter>\n </Router>\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACA,OAAO,WAAW;AAElB,SAAS,cAAc;AAEvB,SAAS,iBAAiB;AAMnB,aAAM,6BAA6B,MAAM,UAAqC;AAAA,EAInF,YAAY,OAAkC;AAC5C,UAAM,KAAK;AACX,SAAK,UAAU,MAAM;AACrB,SAAK,QAAQ,OAAO,KAAK,oBAAoB,KAAK,IAAI,CAAC;AACvD,SAAK,0BAA0B,KAAK,wBAAwB,KAAK,IAAI;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,oBAAoB,UAA2B,QAAuB;AACpE,UAAM,gBAAiB,SAAiB,YAAY;AACpD,UAAM,cAAe,SAAiB,UAAU;AAChD,QAAI,KAAK,sBAAsB;AAC7B,WAAK,qBAAqB,eAAe,WAAW;AAAA,IACtD;AAAA,EACF;AAAA,EAEA,wBAAwB,IAAgE;AACtF,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAU,GAAG,MAAM,IAAI,KAAK;AACpC,WACE,oCAAC,UAAQ,GAAG,SACV,oCAAC,aAAU,yBAAyB,KAAK,2BAA0B,QAAS,CAC9E;AAAA,EAEJ;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { createBrowserHistory as createHistory } from "history";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Router } from "react-router-dom";
|
|
5
|
+
import { IonRouter } from "./IonRouter";
|
|
6
|
+
export class IonReactRouter extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
const { history, ...rest } = props;
|
|
10
|
+
this.history = history || createHistory(rest);
|
|
11
|
+
this.history.listen(this.handleHistoryChange.bind(this));
|
|
12
|
+
this.registerHistoryListener = this.registerHistoryListener.bind(this);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* history@4.x passes separate location and action
|
|
16
|
+
* params. history@5.x passes location and action
|
|
17
|
+
* together as a single object.
|
|
18
|
+
* TODO: If support for React Router <=5 is dropped
|
|
19
|
+
* this logic is no longer needed. We can just assume
|
|
20
|
+
* a single object with both location and action.
|
|
21
|
+
*/
|
|
22
|
+
handleHistoryChange(location, action) {
|
|
23
|
+
const locationValue = location.location || location;
|
|
24
|
+
const actionValue = location.action || action;
|
|
25
|
+
if (this.historyListenHandler) {
|
|
26
|
+
this.historyListenHandler(locationValue, actionValue);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
registerHistoryListener(cb) {
|
|
30
|
+
this.historyListenHandler = cb;
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
const { children, ...props } = this.props;
|
|
34
|
+
return /* @__PURE__ */ React.createElement(Router, { history: this.history, ...props }, /* @__PURE__ */ React.createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=IonReactRouter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ReactRouter/IonReactRouter.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { Action as HistoryAction, History, Location as HistoryLocation } from 'history';\nimport { createBrowserHistory as createHistory } from 'history';\nimport React from 'react';\nimport type { BrowserRouterProps } from 'react-router-dom';\nimport { Router } from 'react-router-dom';\n\nimport { IonRouter } from './IonRouter';\n\ninterface IonReactRouterProps extends BrowserRouterProps {\n history?: History;\n}\n\nexport class IonReactRouter extends React.Component<IonReactRouterProps> {\n historyListenHandler?: (location: HistoryLocation, action: HistoryAction) => void;\n history: History;\n\n constructor(props: IonReactRouterProps) {\n super(props);\n const { history, ...rest } = props;\n this.history = history || createHistory(rest);\n this.history.listen(this.handleHistoryChange.bind(this));\n this.registerHistoryListener = this.registerHistoryListener.bind(this);\n }\n\n /**\n * history@4.x passes separate location and action\n * params. history@5.x passes location and action\n * together as a single object.\n * TODO: If support for React Router <=5 is dropped\n * this logic is no longer needed. We can just assume\n * a single object with both location and action.\n */\n handleHistoryChange(location: HistoryLocation, action: HistoryAction) {\n const locationValue = (location as any).location || location;\n const actionValue = (location as any).action || action;\n if (this.historyListenHandler) {\n this.historyListenHandler(locationValue, actionValue);\n }\n }\n\n registerHistoryListener(cb: (location: HistoryLocation, action: HistoryAction) => void) {\n this.historyListenHandler = cb;\n }\n\n render() {\n const { children, ...props } = this.props;\n return (\n <Router history={this.history} {...props}>\n <IonRouter registerHistoryListener={this.registerHistoryListener}>{children}</IonRouter>\n </Router>\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,wBAAwB,qBAAqB;AACtD,OAAO,WAAW;AAElB,SAAS,cAAc;AAEvB,SAAS,iBAAiB;AAMnB,aAAM,uBAAuB,MAAM,UAA+B;AAAA,EAIvE,YAAY,OAA4B;AACtC,UAAM,KAAK;AACX,UAAM,EAAE,SAAS,GAAG,KAAK,IAAI;AAC7B,SAAK,UAAU,WAAW,cAAc,IAAI;AAC5C,SAAK,QAAQ,OAAO,KAAK,oBAAoB,KAAK,IAAI,CAAC;AACvD,SAAK,0BAA0B,KAAK,wBAAwB,KAAK,IAAI;AAAA,EACvE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,oBAAoB,UAA2B,QAAuB;AACpE,UAAM,gBAAiB,SAAiB,YAAY;AACpD,UAAM,cAAe,SAAiB,UAAU;AAChD,QAAI,KAAK,sBAAsB;AAC7B,WAAK,qBAAqB,eAAe,WAAW;AAAA,IACtD;AAAA,EACF;AAAA,EAEA,wBAAwB,IAAgE;AACtF,SAAK,uBAAuB;AAAA,EAC9B;AAAA,EAEA,SAAS;AACP,UAAM,EAAE,UAAU,GAAG,MAAM,IAAI,KAAK;AACpC,WACE,oCAAC,UAAO,SAAS,KAAK,SAAU,GAAG,SACjC,oCAAC,aAAU,yBAAyB,KAAK,2BAA0B,QAAS,CAC9E;AAAA,EAEJ;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Route } from "react-router";
|
|
4
|
+
export class IonRouteInner extends React.PureComponent {
|
|
5
|
+
render() {
|
|
6
|
+
return /* @__PURE__ */ React.createElement(
|
|
7
|
+
Route,
|
|
8
|
+
{
|
|
9
|
+
path: this.props.path,
|
|
10
|
+
exact: this.props.exact,
|
|
11
|
+
render: this.props.render,
|
|
12
|
+
/**
|
|
13
|
+
* `computedMatch` is a private API in react-router v5 that
|
|
14
|
+
* has been removed in v6.
|
|
15
|
+
*
|
|
16
|
+
* This needs to be removed when we support v6.
|
|
17
|
+
*
|
|
18
|
+
* TODO: FW-647
|
|
19
|
+
*/
|
|
20
|
+
...this.props.computedMatch !== void 0 ? {
|
|
21
|
+
computedMatch: this.props.computedMatch
|
|
22
|
+
} : {}
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=IonRouteInner.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ReactRouter/IonRouteInner.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { IonRouteProps } from '@ionic/react';\nimport React from 'react';\nimport { Route } from 'react-router';\n\nexport class IonRouteInner extends React.PureComponent<IonRouteProps> {\n render() {\n return (\n <Route\n path={this.props.path}\n exact={this.props.exact}\n render={this.props.render}\n {\n /**\n * `computedMatch` is a private API in react-router v5 that\n * has been removed in v6.\n *\n * This needs to be removed when we support v6.\n *\n * TODO: FW-647\n */\n ...((this.props as any).computedMatch !== undefined\n ? {\n computedMatch: (this.props as any).computedMatch,\n }\n : {})\n }\n />\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACA,OAAO,WAAW;AAClB,SAAS,aAAa;AAEf,aAAM,sBAAsB,MAAM,cAA6B;AAAA,EACpE,SAAS;AACP,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAM,KAAK,MAAM;AAAA,QACjB,OAAO,KAAK,MAAM;AAAA,QAClB,QAAQ,KAAK,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAUjB,GAAK,KAAK,MAAc,kBAAkB,SACtC;AAAA,UACE,eAAgB,KAAK,MAAc;AAAA,QACrC,IACA,CAAC;AAAA;AAAA,IAET;AAAA,EAEJ;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { LocationHistory, NavManager, RouteManagerContext, generateId, getConfig } from "@ionic/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { withRouter } from "react-router-dom";
|
|
5
|
+
import { IonRouteInner } from "./IonRouteInner";
|
|
6
|
+
import { ReactRouterViewStack } from "./ReactRouterViewStack";
|
|
7
|
+
import StackManager from "./StackManager";
|
|
8
|
+
class IonRouterInner extends React.PureComponent {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.exitViewFromOtherOutletHandlers = [];
|
|
12
|
+
this.locationHistory = new LocationHistory();
|
|
13
|
+
this.viewStack = new ReactRouterViewStack();
|
|
14
|
+
this.routeMangerContextState = {
|
|
15
|
+
canGoBack: () => this.locationHistory.canGoBack(),
|
|
16
|
+
clearOutlet: this.viewStack.clear,
|
|
17
|
+
findViewItemByPathname: this.viewStack.findViewItemByPathname,
|
|
18
|
+
getChildrenToRender: this.viewStack.getChildrenToRender,
|
|
19
|
+
goBack: () => this.handleNavigateBack(),
|
|
20
|
+
createViewItem: this.viewStack.createViewItem,
|
|
21
|
+
findViewItemByRouteInfo: this.viewStack.findViewItemByRouteInfo,
|
|
22
|
+
findLeavingViewItemByRouteInfo: this.viewStack.findLeavingViewItemByRouteInfo,
|
|
23
|
+
addViewItem: this.viewStack.add,
|
|
24
|
+
unMountViewItem: this.viewStack.remove
|
|
25
|
+
};
|
|
26
|
+
const routeInfo = {
|
|
27
|
+
id: generateId("routeInfo"),
|
|
28
|
+
pathname: this.props.location.pathname,
|
|
29
|
+
search: this.props.location.search
|
|
30
|
+
};
|
|
31
|
+
this.locationHistory.add(routeInfo);
|
|
32
|
+
this.handleChangeTab = this.handleChangeTab.bind(this);
|
|
33
|
+
this.handleResetTab = this.handleResetTab.bind(this);
|
|
34
|
+
this.handleNativeBack = this.handleNativeBack.bind(this);
|
|
35
|
+
this.handleNavigate = this.handleNavigate.bind(this);
|
|
36
|
+
this.handleNavigateBack = this.handleNavigateBack.bind(this);
|
|
37
|
+
this.props.registerHistoryListener(this.handleHistoryChange.bind(this));
|
|
38
|
+
this.handleSetCurrentTab = this.handleSetCurrentTab.bind(this);
|
|
39
|
+
this.state = {
|
|
40
|
+
routeInfo
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
handleChangeTab(tab, path, routeOptions) {
|
|
44
|
+
if (!path) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const routeInfo = this.locationHistory.getCurrentRouteInfoForTab(tab);
|
|
48
|
+
const [pathname, search] = path.split("?");
|
|
49
|
+
if (routeInfo) {
|
|
50
|
+
this.incomingRouteParams = { ...routeInfo, routeAction: "push", routeDirection: "none" };
|
|
51
|
+
if (routeInfo.pathname === pathname) {
|
|
52
|
+
this.incomingRouteParams.routeOptions = routeOptions;
|
|
53
|
+
this.props.history.push(routeInfo.pathname + (routeInfo.search || ""));
|
|
54
|
+
} else {
|
|
55
|
+
this.incomingRouteParams.pathname = pathname;
|
|
56
|
+
this.incomingRouteParams.search = search ? "?" + search : void 0;
|
|
57
|
+
this.incomingRouteParams.routeOptions = routeOptions;
|
|
58
|
+
this.props.history.push(pathname + (search ? "?" + search : ""));
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
this.handleNavigate(pathname, "push", "none", void 0, routeOptions, tab);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
handleHistoryChange(location, action) {
|
|
65
|
+
let leavingLocationInfo;
|
|
66
|
+
if (this.incomingRouteParams) {
|
|
67
|
+
if (this.incomingRouteParams.routeAction === "replace") {
|
|
68
|
+
leavingLocationInfo = this.locationHistory.previous();
|
|
69
|
+
} else {
|
|
70
|
+
leavingLocationInfo = this.locationHistory.current();
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
leavingLocationInfo = this.locationHistory.current();
|
|
74
|
+
}
|
|
75
|
+
const leavingUrl = leavingLocationInfo.pathname + leavingLocationInfo.search;
|
|
76
|
+
if (leavingUrl !== location.pathname) {
|
|
77
|
+
if (!this.incomingRouteParams) {
|
|
78
|
+
if (action === "REPLACE") {
|
|
79
|
+
this.incomingRouteParams = {
|
|
80
|
+
routeAction: "replace",
|
|
81
|
+
routeDirection: "none",
|
|
82
|
+
tab: this.currentTab
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (action === "POP") {
|
|
86
|
+
const currentRoute = this.locationHistory.current();
|
|
87
|
+
if (currentRoute && currentRoute.pushedByRoute) {
|
|
88
|
+
const prevInfo = this.locationHistory.findLastLocation(currentRoute);
|
|
89
|
+
this.incomingRouteParams = { ...prevInfo, routeAction: "pop", routeDirection: "back" };
|
|
90
|
+
} else {
|
|
91
|
+
this.incomingRouteParams = {
|
|
92
|
+
routeAction: "pop",
|
|
93
|
+
routeDirection: "none",
|
|
94
|
+
tab: this.currentTab
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!this.incomingRouteParams) {
|
|
99
|
+
this.incomingRouteParams = {
|
|
100
|
+
routeAction: "push",
|
|
101
|
+
routeDirection: location.state?.direction || "forward",
|
|
102
|
+
routeOptions: location.state?.routerOptions,
|
|
103
|
+
tab: this.currentTab
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
let routeInfo;
|
|
108
|
+
if (this.incomingRouteParams?.id) {
|
|
109
|
+
routeInfo = {
|
|
110
|
+
...this.incomingRouteParams,
|
|
111
|
+
lastPathname: leavingLocationInfo.pathname
|
|
112
|
+
};
|
|
113
|
+
this.locationHistory.add(routeInfo);
|
|
114
|
+
} else {
|
|
115
|
+
const isPushed = this.incomingRouteParams.routeAction === "push" && this.incomingRouteParams.routeDirection === "forward";
|
|
116
|
+
routeInfo = {
|
|
117
|
+
id: generateId("routeInfo"),
|
|
118
|
+
...this.incomingRouteParams,
|
|
119
|
+
lastPathname: leavingLocationInfo.pathname,
|
|
120
|
+
pathname: location.pathname,
|
|
121
|
+
search: location.search,
|
|
122
|
+
params: this.props.match.params,
|
|
123
|
+
prevRouteLastPathname: leavingLocationInfo.lastPathname
|
|
124
|
+
};
|
|
125
|
+
if (isPushed) {
|
|
126
|
+
routeInfo.tab = leavingLocationInfo.tab;
|
|
127
|
+
routeInfo.pushedByRoute = leavingLocationInfo.pathname;
|
|
128
|
+
} else if (routeInfo.routeAction === "pop") {
|
|
129
|
+
const r = this.locationHistory.findLastLocation(routeInfo);
|
|
130
|
+
routeInfo.pushedByRoute = r?.pushedByRoute;
|
|
131
|
+
} else if (routeInfo.routeAction === "push" && routeInfo.tab !== leavingLocationInfo.tab) {
|
|
132
|
+
const lastRoute = this.locationHistory.getCurrentRouteInfoForTab(routeInfo.tab);
|
|
133
|
+
routeInfo.pushedByRoute = lastRoute?.pushedByRoute;
|
|
134
|
+
} else if (routeInfo.routeAction === "replace") {
|
|
135
|
+
const currentRouteInfo = this.locationHistory.current();
|
|
136
|
+
const currentPushedBy = currentRouteInfo?.pushedByRoute;
|
|
137
|
+
const pushedByRoute = currentPushedBy !== void 0 && currentPushedBy !== routeInfo.pathname ? currentPushedBy : routeInfo.pushedByRoute;
|
|
138
|
+
routeInfo.lastPathname = currentRouteInfo?.pathname || routeInfo.lastPathname;
|
|
139
|
+
routeInfo.prevRouteLastPathname = currentRouteInfo?.lastPathname;
|
|
140
|
+
routeInfo.pushedByRoute = pushedByRoute;
|
|
141
|
+
routeInfo.routeDirection = currentRouteInfo?.routeDirection || routeInfo.routeDirection;
|
|
142
|
+
routeInfo.routeAnimation = currentRouteInfo?.routeAnimation || routeInfo.routeAnimation;
|
|
143
|
+
}
|
|
144
|
+
this.locationHistory.add(routeInfo);
|
|
145
|
+
}
|
|
146
|
+
this.setState({
|
|
147
|
+
routeInfo
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
this.incomingRouteParams = void 0;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* history@4.x uses goBack(), history@5.x uses back()
|
|
154
|
+
* TODO: If support for React Router <=5 is dropped
|
|
155
|
+
* this logic is no longer needed. We can just
|
|
156
|
+
* assume back() is available.
|
|
157
|
+
*/
|
|
158
|
+
handleNativeBack() {
|
|
159
|
+
const history = this.props.history;
|
|
160
|
+
const goBack = history.goBack || history.back;
|
|
161
|
+
goBack();
|
|
162
|
+
}
|
|
163
|
+
handleNavigate(path, routeAction, routeDirection, routeAnimation, routeOptions, tab) {
|
|
164
|
+
this.incomingRouteParams = Object.assign(this.incomingRouteParams || {}, {
|
|
165
|
+
routeAction,
|
|
166
|
+
routeDirection,
|
|
167
|
+
routeOptions,
|
|
168
|
+
routeAnimation,
|
|
169
|
+
tab
|
|
170
|
+
});
|
|
171
|
+
if (routeAction === "push") {
|
|
172
|
+
this.props.history.push(path);
|
|
173
|
+
} else {
|
|
174
|
+
this.props.history.replace(path);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
handleNavigateBack(defaultHref = "/", routeAnimation) {
|
|
178
|
+
const config = getConfig();
|
|
179
|
+
defaultHref = defaultHref ? defaultHref : config && config.get("backButtonDefaultHref");
|
|
180
|
+
const routeInfo = this.locationHistory.current();
|
|
181
|
+
if (routeInfo && routeInfo.pushedByRoute) {
|
|
182
|
+
const prevInfo = this.locationHistory.findLastLocation(routeInfo);
|
|
183
|
+
if (prevInfo) {
|
|
184
|
+
this.incomingRouteParams = {
|
|
185
|
+
...prevInfo,
|
|
186
|
+
routeAction: "pop",
|
|
187
|
+
routeDirection: "back",
|
|
188
|
+
routeAnimation: routeAnimation || routeInfo.routeAnimation
|
|
189
|
+
};
|
|
190
|
+
if (routeInfo.lastPathname === routeInfo.pushedByRoute || /**
|
|
191
|
+
* We need to exclude tab switches/tab
|
|
192
|
+
* context changes here because tabbed
|
|
193
|
+
* navigation is not linear, but router.back()
|
|
194
|
+
* will go back in a linear fashion.
|
|
195
|
+
*/
|
|
196
|
+
prevInfo.pathname === routeInfo.pushedByRoute && routeInfo.tab === "" && prevInfo.tab === "") {
|
|
197
|
+
const history = this.props.history;
|
|
198
|
+
const goBack = history.goBack || history.back;
|
|
199
|
+
goBack();
|
|
200
|
+
} else {
|
|
201
|
+
this.handleNavigate(prevInfo.pathname + (prevInfo.search || ""), "pop", "back", routeAnimation);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
this.handleNavigate(defaultHref, "pop", "back", routeAnimation);
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
this.handleNavigate(defaultHref, "pop", "back", routeAnimation);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
handleResetTab(tab, originalHref, originalRouteOptions) {
|
|
211
|
+
const routeInfo = this.locationHistory.getFirstRouteInfoForTab(tab);
|
|
212
|
+
if (routeInfo) {
|
|
213
|
+
const newRouteInfo = { ...routeInfo };
|
|
214
|
+
newRouteInfo.pathname = originalHref;
|
|
215
|
+
newRouteInfo.routeOptions = originalRouteOptions;
|
|
216
|
+
this.incomingRouteParams = { ...newRouteInfo, routeAction: "pop", routeDirection: "back" };
|
|
217
|
+
this.props.history.push(newRouteInfo.pathname + (newRouteInfo.search || ""));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
handleSetCurrentTab(tab) {
|
|
221
|
+
this.currentTab = tab;
|
|
222
|
+
const ri = { ...this.locationHistory.current() };
|
|
223
|
+
if (ri.tab !== tab) {
|
|
224
|
+
ri.tab = tab;
|
|
225
|
+
this.locationHistory.update(ri);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
render() {
|
|
229
|
+
return /* @__PURE__ */ React.createElement(RouteManagerContext.Provider, { value: this.routeMangerContextState }, /* @__PURE__ */ React.createElement(
|
|
230
|
+
NavManager,
|
|
231
|
+
{
|
|
232
|
+
ionRoute: IonRouteInner,
|
|
233
|
+
ionRedirect: {},
|
|
234
|
+
stackManager: StackManager,
|
|
235
|
+
routeInfo: this.state.routeInfo,
|
|
236
|
+
onNativeBack: this.handleNativeBack,
|
|
237
|
+
onNavigateBack: this.handleNavigateBack,
|
|
238
|
+
onNavigate: this.handleNavigate,
|
|
239
|
+
onSetCurrentTab: this.handleSetCurrentTab,
|
|
240
|
+
onChangeTab: this.handleChangeTab,
|
|
241
|
+
onResetTab: this.handleResetTab,
|
|
242
|
+
locationHistory: this.locationHistory
|
|
243
|
+
},
|
|
244
|
+
this.props.children
|
|
245
|
+
));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
export const IonRouter = withRouter(IonRouterInner);
|
|
249
|
+
IonRouter.displayName = "IonRouter";
|
|
250
|
+
//# sourceMappingURL=IonRouter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ReactRouter/IonRouter.tsx"],
|
|
4
|
+
"sourcesContent": ["import type {\n AnimationBuilder,\n RouteAction,\n RouteInfo,\n RouteManagerContextState,\n RouterDirection,\n ViewItem,\n} from '@ionic/react';\nimport { LocationHistory, NavManager, RouteManagerContext, generateId, getConfig } from '@ionic/react';\nimport type { Action as HistoryAction, Location as HistoryLocation } from 'history';\nimport React from 'react';\nimport type { RouteComponentProps } from 'react-router-dom';\nimport { withRouter } from 'react-router-dom';\n\nimport { IonRouteInner } from './IonRouteInner';\nimport { ReactRouterViewStack } from './ReactRouterViewStack';\nimport StackManager from './StackManager';\n\nexport interface LocationState {\n direction?: RouterDirection;\n routerOptions?: { as?: string; unmount?: boolean };\n}\n\ninterface IonRouteProps extends RouteComponentProps<{}, {}, LocationState> {\n registerHistoryListener: (cb: (location: HistoryLocation<any>, action: HistoryAction) => void) => void;\n}\n\ninterface IonRouteState {\n routeInfo: RouteInfo;\n}\n\nclass IonRouterInner extends React.PureComponent<IonRouteProps, IonRouteState> {\n currentTab?: string;\n exitViewFromOtherOutletHandlers: ((pathname: string) => ViewItem | undefined)[] = [];\n incomingRouteParams?: Partial<RouteInfo>;\n locationHistory = new LocationHistory();\n viewStack = new ReactRouterViewStack();\n routeMangerContextState: RouteManagerContextState = {\n canGoBack: () => this.locationHistory.canGoBack(),\n clearOutlet: this.viewStack.clear,\n findViewItemByPathname: this.viewStack.findViewItemByPathname,\n getChildrenToRender: this.viewStack.getChildrenToRender,\n goBack: () => this.handleNavigateBack(),\n createViewItem: this.viewStack.createViewItem,\n findViewItemByRouteInfo: this.viewStack.findViewItemByRouteInfo,\n findLeavingViewItemByRouteInfo: this.viewStack.findLeavingViewItemByRouteInfo,\n addViewItem: this.viewStack.add,\n unMountViewItem: this.viewStack.remove,\n };\n\n constructor(props: IonRouteProps) {\n super(props);\n\n const routeInfo = {\n id: generateId('routeInfo'),\n pathname: this.props.location.pathname,\n search: this.props.location.search,\n };\n\n this.locationHistory.add(routeInfo);\n this.handleChangeTab = this.handleChangeTab.bind(this);\n this.handleResetTab = this.handleResetTab.bind(this);\n this.handleNativeBack = this.handleNativeBack.bind(this);\n this.handleNavigate = this.handleNavigate.bind(this);\n this.handleNavigateBack = this.handleNavigateBack.bind(this);\n this.props.registerHistoryListener(this.handleHistoryChange.bind(this));\n this.handleSetCurrentTab = this.handleSetCurrentTab.bind(this);\n\n this.state = {\n routeInfo,\n };\n }\n\n handleChangeTab(tab: string, path?: string, routeOptions?: any) {\n if (!path) {\n return;\n }\n\n const routeInfo = this.locationHistory.getCurrentRouteInfoForTab(tab);\n const [pathname, search] = path.split('?');\n if (routeInfo) {\n this.incomingRouteParams = { ...routeInfo, routeAction: 'push', routeDirection: 'none' };\n if (routeInfo.pathname === pathname) {\n this.incomingRouteParams.routeOptions = routeOptions;\n this.props.history.push(routeInfo.pathname + (routeInfo.search || ''));\n } else {\n this.incomingRouteParams.pathname = pathname;\n this.incomingRouteParams.search = search ? '?' + search : undefined;\n this.incomingRouteParams.routeOptions = routeOptions;\n this.props.history.push(pathname + (search ? '?' + search : ''));\n }\n } else {\n this.handleNavigate(pathname, 'push', 'none', undefined, routeOptions, tab);\n }\n }\n\n handleHistoryChange(location: HistoryLocation<LocationState>, action: HistoryAction) {\n let leavingLocationInfo: RouteInfo;\n if (this.incomingRouteParams) {\n if (this.incomingRouteParams.routeAction === 'replace') {\n leavingLocationInfo = this.locationHistory.previous();\n } else {\n leavingLocationInfo = this.locationHistory.current();\n }\n } else {\n leavingLocationInfo = this.locationHistory.current();\n }\n\n const leavingUrl = leavingLocationInfo.pathname + leavingLocationInfo.search;\n if (leavingUrl !== location.pathname) {\n if (!this.incomingRouteParams) {\n if (action === 'REPLACE') {\n this.incomingRouteParams = {\n routeAction: 'replace',\n routeDirection: 'none',\n tab: this.currentTab,\n };\n }\n if (action === 'POP') {\n const currentRoute = this.locationHistory.current();\n if (currentRoute && currentRoute.pushedByRoute) {\n const prevInfo = this.locationHistory.findLastLocation(currentRoute);\n this.incomingRouteParams = { ...prevInfo, routeAction: 'pop', routeDirection: 'back' };\n } else {\n this.incomingRouteParams = {\n routeAction: 'pop',\n routeDirection: 'none',\n tab: this.currentTab,\n };\n }\n }\n if (!this.incomingRouteParams) {\n this.incomingRouteParams = {\n routeAction: 'push',\n routeDirection: location.state?.direction || 'forward',\n routeOptions: location.state?.routerOptions,\n tab: this.currentTab,\n };\n }\n }\n\n let routeInfo: RouteInfo;\n\n if (this.incomingRouteParams?.id) {\n routeInfo = {\n ...(this.incomingRouteParams as RouteInfo),\n lastPathname: leavingLocationInfo.pathname,\n };\n this.locationHistory.add(routeInfo);\n } else {\n const isPushed =\n this.incomingRouteParams.routeAction === 'push' && this.incomingRouteParams.routeDirection === 'forward';\n routeInfo = {\n id: generateId('routeInfo'),\n ...this.incomingRouteParams,\n lastPathname: leavingLocationInfo.pathname,\n pathname: location.pathname,\n search: location.search,\n params: this.props.match.params,\n prevRouteLastPathname: leavingLocationInfo.lastPathname,\n };\n if (isPushed) {\n routeInfo.tab = leavingLocationInfo.tab;\n routeInfo.pushedByRoute = leavingLocationInfo.pathname;\n } else if (routeInfo.routeAction === 'pop') {\n const r = this.locationHistory.findLastLocation(routeInfo);\n routeInfo.pushedByRoute = r?.pushedByRoute;\n } else if (routeInfo.routeAction === 'push' && routeInfo.tab !== leavingLocationInfo.tab) {\n // If we are switching tabs grab the last route info for the tab and use its pushedByRoute\n const lastRoute = this.locationHistory.getCurrentRouteInfoForTab(routeInfo.tab);\n routeInfo.pushedByRoute = lastRoute?.pushedByRoute;\n } else if (routeInfo.routeAction === 'replace') {\n // Make sure to set the lastPathname, etc.. to the current route so the page transitions out\n const currentRouteInfo = this.locationHistory.current();\n\n /**\n * If going from /home to /child, then replacing from\n * /child to /home, we don't want the route info to\n * say that /home was pushed by /home which is not correct.\n */\n const currentPushedBy = currentRouteInfo?.pushedByRoute;\n const pushedByRoute =\n currentPushedBy !== undefined && currentPushedBy !== routeInfo.pathname\n ? currentPushedBy\n : routeInfo.pushedByRoute;\n\n routeInfo.lastPathname = currentRouteInfo?.pathname || routeInfo.lastPathname;\n routeInfo.prevRouteLastPathname = currentRouteInfo?.lastPathname;\n routeInfo.pushedByRoute = pushedByRoute;\n routeInfo.routeDirection = currentRouteInfo?.routeDirection || routeInfo.routeDirection;\n routeInfo.routeAnimation = currentRouteInfo?.routeAnimation || routeInfo.routeAnimation;\n }\n\n this.locationHistory.add(routeInfo);\n }\n\n this.setState({\n routeInfo,\n });\n }\n\n this.incomingRouteParams = undefined;\n }\n\n /**\n * history@4.x uses goBack(), history@5.x uses back()\n * TODO: If support for React Router <=5 is dropped\n * this logic is no longer needed. We can just\n * assume back() is available.\n */\n handleNativeBack() {\n const history = this.props.history as any;\n const goBack = history.goBack || history.back;\n goBack();\n }\n\n handleNavigate(\n path: string,\n routeAction: RouteAction,\n routeDirection?: RouterDirection,\n routeAnimation?: AnimationBuilder,\n routeOptions?: any,\n tab?: string\n ) {\n this.incomingRouteParams = Object.assign(this.incomingRouteParams || {}, {\n routeAction,\n routeDirection,\n routeOptions,\n routeAnimation,\n tab,\n });\n\n if (routeAction === 'push') {\n this.props.history.push(path);\n } else {\n this.props.history.replace(path);\n }\n }\n\n handleNavigateBack(defaultHref: string | RouteInfo = '/', routeAnimation?: AnimationBuilder) {\n const config = getConfig();\n defaultHref = defaultHref ? defaultHref : config && config.get('backButtonDefaultHref' as any);\n const routeInfo = this.locationHistory.current();\n if (routeInfo && routeInfo.pushedByRoute) {\n const prevInfo = this.locationHistory.findLastLocation(routeInfo);\n if (prevInfo) {\n this.incomingRouteParams = {\n ...prevInfo,\n routeAction: 'pop',\n routeDirection: 'back',\n routeAnimation: routeAnimation || routeInfo.routeAnimation,\n };\n if (\n routeInfo.lastPathname === routeInfo.pushedByRoute ||\n /**\n * We need to exclude tab switches/tab\n * context changes here because tabbed\n * navigation is not linear, but router.back()\n * will go back in a linear fashion.\n */\n (prevInfo.pathname === routeInfo.pushedByRoute && routeInfo.tab === '' && prevInfo.tab === '')\n ) {\n /**\n * history@4.x uses goBack(), history@5.x uses back()\n * TODO: If support for React Router <=5 is dropped\n * this logic is no longer needed. We can just\n * assume back() is available.\n */\n const history = this.props.history as any;\n const goBack = history.goBack || history.back;\n goBack();\n } else {\n this.handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back', routeAnimation);\n }\n } else {\n this.handleNavigate(defaultHref as string, 'pop', 'back', routeAnimation);\n }\n } else {\n this.handleNavigate(defaultHref as string, 'pop', 'back', routeAnimation);\n }\n }\n\n handleResetTab(tab: string, originalHref: string, originalRouteOptions: any) {\n const routeInfo = this.locationHistory.getFirstRouteInfoForTab(tab);\n if (routeInfo) {\n const newRouteInfo = { ...routeInfo };\n newRouteInfo.pathname = originalHref;\n newRouteInfo.routeOptions = originalRouteOptions;\n this.incomingRouteParams = { ...newRouteInfo, routeAction: 'pop', routeDirection: 'back' };\n this.props.history.push(newRouteInfo.pathname + (newRouteInfo.search || ''));\n }\n }\n\n handleSetCurrentTab(tab: string) {\n this.currentTab = tab;\n const ri = { ...this.locationHistory.current() };\n if (ri.tab !== tab) {\n ri.tab = tab;\n this.locationHistory.update(ri);\n }\n }\n\n render() {\n return (\n <RouteManagerContext.Provider value={this.routeMangerContextState}>\n <NavManager\n ionRoute={IonRouteInner}\n ionRedirect={{}}\n stackManager={StackManager}\n routeInfo={this.state.routeInfo!}\n onNativeBack={this.handleNativeBack}\n onNavigateBack={this.handleNavigateBack}\n onNavigate={this.handleNavigate}\n onSetCurrentTab={this.handleSetCurrentTab}\n onChangeTab={this.handleChangeTab}\n onResetTab={this.handleResetTab}\n locationHistory={this.locationHistory}\n >\n {this.props.children}\n </NavManager>\n </RouteManagerContext.Provider>\n );\n }\n}\n\nexport const IonRouter = withRouter(IonRouterInner);\nIonRouter.displayName = 'IonRouter';\n"],
|
|
5
|
+
"mappings": ";AAQA,SAAS,iBAAiB,YAAY,qBAAqB,YAAY,iBAAiB;AAExF,OAAO,WAAW;AAElB,SAAS,kBAAkB;AAE3B,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;AACrC,OAAO,kBAAkB;AAezB,MAAM,uBAAuB,MAAM,cAA4C;AAAA,EAmB7E,YAAY,OAAsB;AAChC,UAAM,KAAK;AAlBb,2CAAkF,CAAC;AAEnF,2BAAkB,IAAI,gBAAgB;AACtC,qBAAY,IAAI,qBAAqB;AACrC,mCAAoD;AAAA,MAClD,WAAW,MAAM,KAAK,gBAAgB,UAAU;AAAA,MAChD,aAAa,KAAK,UAAU;AAAA,MAC5B,wBAAwB,KAAK,UAAU;AAAA,MACvC,qBAAqB,KAAK,UAAU;AAAA,MACpC,QAAQ,MAAM,KAAK,mBAAmB;AAAA,MACtC,gBAAgB,KAAK,UAAU;AAAA,MAC/B,yBAAyB,KAAK,UAAU;AAAA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ks, generateId } from "@ionic/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { matchPath } from "react-router";
|
|
5
|
+
export class ReactRouterViewStack extends ViewStacks {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.createViewItem = this.createViewItem.bind(this);
|
|
9
|
+
this.findViewItemByRouteInfo = this.findViewItemByRouteInfo.bind(this);
|
|
10
|
+
this.findLeavingViewItemByRouteInfo = this.findLeavingViewItemByRouteInfo.bind(this);
|
|
11
|
+
this.getChildrenToRender = this.getChildrenToRender.bind(this);
|
|
12
|
+
this.findViewItemByPathname = this.findViewItemByPathname.bind(this);
|
|
13
|
+
}
|
|
14
|
+
createViewItem(outletId, reactElement, routeInfo, page) {
|
|
15
|
+
const viewItem = {
|
|
16
|
+
id: generateId("viewItem"),
|
|
17
|
+
outletId,
|
|
18
|
+
ionPageElement: page,
|
|
19
|
+
reactElement,
|
|
20
|
+
mount: true,
|
|
21
|
+
ionRoute: false
|
|
22
|
+
};
|
|
23
|
+
const matchProps = {
|
|
24
|
+
exact: reactElement.props.exact,
|
|
25
|
+
path: reactElement.props.path || reactElement.props.from,
|
|
26
|
+
component: reactElement.props.component
|
|
27
|
+
};
|
|
28
|
+
const match = matchPath(routeInfo.pathname, matchProps);
|
|
29
|
+
if (reactElement.type === IonRoute) {
|
|
30
|
+
viewItem.ionRoute = true;
|
|
31
|
+
viewItem.disableIonPageManagement = reactElement.props.disableIonPageManagement;
|
|
32
|
+
}
|
|
33
|
+
viewItem.routeData = {
|
|
34
|
+
match,
|
|
35
|
+
childProps: reactElement.props
|
|
36
|
+
};
|
|
37
|
+
return viewItem;
|
|
38
|
+
}
|
|
39
|
+
getChildrenToRender(outletId, ionRouterOutlet, routeInfo) {
|
|
40
|
+
const viewItems = this.getViewItemsForOutlet(outletId);
|
|
41
|
+
React.Children.forEach(ionRouterOutlet.props.children, (child) => {
|
|
42
|
+
const viewItem = viewItems.find((v) => {
|
|
43
|
+
return matchComponent(child, v.routeData.childProps.path || v.routeData.childProps.from);
|
|
44
|
+
});
|
|
45
|
+
if (viewItem) {
|
|
46
|
+
viewItem.reactElement = child;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const children = viewItems.map((viewItem) => {
|
|
50
|
+
let clonedChild;
|
|
51
|
+
if (viewItem.ionRoute && !viewItem.disableIonPageManagement) {
|
|
52
|
+
clonedChild = /* @__PURE__ */ React.createElement(
|
|
53
|
+
ViewLifeCycleManager,
|
|
54
|
+
{
|
|
55
|
+
key: `view-${viewItem.id}`,
|
|
56
|
+
mount: viewItem.mount,
|
|
57
|
+
removeView: () => this.remove(viewItem)
|
|
58
|
+
},
|
|
59
|
+
React.cloneElement(viewItem.reactElement, {
|
|
60
|
+
computedMatch: viewItem.routeData.match
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
const match = matchComponent(viewItem.reactElement, routeInfo.pathname);
|
|
65
|
+
clonedChild = /* @__PURE__ */ React.createElement(
|
|
66
|
+
ViewLifeCycleManager,
|
|
67
|
+
{
|
|
68
|
+
key: `view-${viewItem.id}`,
|
|
69
|
+
mount: viewItem.mount,
|
|
70
|
+
removeView: () => this.remove(viewItem)
|
|
71
|
+
},
|
|
72
|
+
React.cloneElement(viewItem.reactElement, {
|
|
73
|
+
computedMatch: viewItem.routeData.match
|
|
74
|
+
})
|
|
75
|
+
);
|
|
76
|
+
if (!match && viewItem.routeData.match) {
|
|
77
|
+
viewItem.routeData.match = void 0;
|
|
78
|
+
viewItem.mount = false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return clonedChild;
|
|
82
|
+
});
|
|
83
|
+
return children;
|
|
84
|
+
}
|
|
85
|
+
findViewItemByRouteInfo(routeInfo, outletId, updateMatch) {
|
|
86
|
+
const { viewItem, match } = this.findViewItemByPath(routeInfo.pathname, outletId);
|
|
87
|
+
const shouldUpdateMatch = updateMatch === void 0 || updateMatch === true;
|
|
88
|
+
if (shouldUpdateMatch && viewItem && match) {
|
|
89
|
+
viewItem.routeData.match = match;
|
|
90
|
+
}
|
|
91
|
+
return viewItem;
|
|
92
|
+
}
|
|
93
|
+
findLeavingViewItemByRouteInfo(routeInfo, outletId, mustBeIonRoute = true) {
|
|
94
|
+
const { viewItem } = this.findViewItemByPath(routeInfo.lastPathname, outletId, false, mustBeIonRoute);
|
|
95
|
+
return viewItem;
|
|
96
|
+
}
|
|
97
|
+
findViewItemByPathname(pathname, outletId) {
|
|
98
|
+
const { viewItem } = this.findViewItemByPath(pathname, outletId);
|
|
99
|
+
return viewItem;
|
|
100
|
+
}
|
|
101
|
+
findViewItemByPath(pathname, outletId, forceExact, mustBeIonRoute) {
|
|
102
|
+
let viewItem;
|
|
103
|
+
let match;
|
|
104
|
+
let viewStack;
|
|
105
|
+
if (outletId) {
|
|
106
|
+
viewStack = this.getViewItemsForOutlet(outletId);
|
|
107
|
+
viewStack.some(matchView);
|
|
108
|
+
if (!viewItem) {
|
|
109
|
+
viewStack.some(matchDefaultRoute);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
const viewItems = this.getAllViewItems();
|
|
113
|
+
viewItems.some(matchView);
|
|
114
|
+
if (!viewItem) {
|
|
115
|
+
viewItems.some(matchDefaultRoute);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return { viewItem, match };
|
|
119
|
+
function matchView(v) {
|
|
120
|
+
if (mustBeIonRoute && !v.ionRoute) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
const matchProps = {
|
|
124
|
+
exact: forceExact ? true : v.routeData.childProps.exact,
|
|
125
|
+
path: v.routeData.childProps.path || v.routeData.childProps.from,
|
|
126
|
+
component: v.routeData.childProps.component
|
|
127
|
+
};
|
|
128
|
+
const myMatch = matchPath(pathname, matchProps);
|
|
129
|
+
if (myMatch) {
|
|
130
|
+
viewItem = v;
|
|
131
|
+
match = myMatch;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
function matchDefaultRoute(v) {
|
|
137
|
+
if (!v.routeData.childProps.path && !v.routeData.childProps.from) {
|
|
138
|
+
match = {
|
|
139
|
+
path: pathname,
|
|
140
|
+
url: pathname,
|
|
141
|
+
isExact: true,
|
|
142
|
+
params: {}
|
|
143
|
+
};
|
|
144
|
+
viewItem = v;
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function matchComponent(node, pathname, forceExact) {
|
|
152
|
+
const matchProps = {
|
|
153
|
+
exact: forceExact ? true : node.props.exact,
|
|
154
|
+
path: node.props.path || node.props.from,
|
|
155
|
+
component: node.props.component
|
|
156
|
+
};
|
|
157
|
+
const match = matchPath(pathname, matchProps);
|
|
158
|
+
return match;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=ReactRouterViewStack.js.map
|