Skip to content

Commit c897c57

Browse files
author
orchoban
committed
prop changeRoute
1 parent 540fa26 commit c897c57

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ options => { animationIn:integer // have defult
9898
<td>(goToPageKey,levelAction) => { ... }</td>
9999
</tr>
100100
<tr>
101+
<tr>
102+
<td>changeRoute</td>
103+
<td>boolean</td>
104+
<td>optional</td>
105+
<td>true (on cordova native platforms => false)</td>
106+
<td>Determines whether to change the URL to the component key</td>
107+
</tr>
101108
<td>homePageKey</td>
102109
<td>string</td>
103110
<td>optional</td>

dist/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ var Navigator = function (_React$Component) {
4444

4545
var homePage = _this.props.homePageKey ? _this.props.homePageKey : Array.isArray(_this.props.children) ? _this.props.children[0].key : _this.props.children.key;
4646

47-
if (mobileMode) {
47+
var changeRoute = true; //default
48+
if (mobileMode) changeRoute = false;
49+
if (_this.props.changeRoute !== undefined) changeRoute = _this.props.changeRoute;
50+
51+
if (!changeRoute) {
4852
startPage = homePage;
4953
} else {
5054

@@ -59,6 +63,7 @@ var Navigator = function (_React$Component) {
5963
if (startPage !== homePage) historyPages.push(startPage);
6064

6165
_this.state = {
66+
changeRoute: changeRoute,
6267
historyPages: historyPages,
6368
nowPage: startPage,
6469
homePageKey: homePage,
@@ -247,7 +252,10 @@ var Navigator = function (_React$Component) {
247252
this.setState({ historyPages: new_historyPages });
248253
}
249254

250-
if (!window.cordova) window.location.href = window.location.href.substr(0, window.location.href.lastIndexOf("/") + 1) + "#" + (goToPage !== this.state.homePageKey ? goToPage : "");else if (window.cordova.platformId === "browser") window.location.href = window.location.href.substr(0, window.location.href.lastIndexOf("/") + 1) + "#" + (goToPage !== this.state.homePageKey ? goToPage : "");
255+
if (this.state.changeRoute) {
256+
257+
window.location.href = window.location.href.substr(0, window.location.href.lastIndexOf("/") + 1) + "#" + (goToPage !== this.state.homePageKey ? goToPage : "");
258+
}
251259

252260
//----navigator and animation----///
253261

@@ -291,7 +299,7 @@ var Navigator = function (_React$Component) {
291299
key: 'componentWillMount',
292300
value: function componentWillMount() {
293301
var fthis = this;
294-
if (fthis.state.mobileMode) {
302+
if (!fthis.state.changeRoute) {
295303

296304
// //---lock portrait
297305
// window.screen.orientation.lock('portrait');
@@ -346,7 +354,6 @@ var Navigator = function (_React$Component) {
346354
'div',
347355
{
348356
onTouchStart: function onTouchStart(e) {
349-
350357
if (child.props.backOnSwipeRight) {
351358
if (e.touches[0].clientX < 0.20 * innerWidth) {
352359
fthis.touchBackPage = nowPage;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react.cordova-navigation_controller",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "Navigator for Cordova with React.js(react.cordova), This will help you to manage your pages history in the app and change pages with animation.",
55
"main": "dist/index.js",
66
"scripts": {

src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ export default class Navigator extends React.Component {
2121
? this.props.children[0].key
2222
: this.props.children.key;
2323

24+
let changeRoute = true;//default
25+
if (mobileMode)
26+
changeRoute = false;
27+
if (this.props.changeRoute !== undefined)
28+
changeRoute = this.props.changeRoute;
2429

25-
if (mobileMode) {
30+
if (!changeRoute) {
2631
startPage = homePage;
2732
} else {
2833

@@ -45,6 +50,7 @@ export default class Navigator extends React.Component {
4550

4651

4752
this.state = {
53+
changeRoute: changeRoute,
4854
historyPages: historyPages,
4955
nowPage: startPage,
5056
homePageKey: homePage,
@@ -243,15 +249,12 @@ export default class Navigator extends React.Component {
243249
this.setState({ historyPages: new_historyPages });
244250
}
245251

246-
if (!window.cordova)
252+
if (this.state.changeRoute) {
247253

248254
window.location.href = window.location.href.substr(0,
249255
window.location.href.lastIndexOf("/") + 1) +
250256
"#" + (goToPage !== this.state.homePageKey ? goToPage : "");
251-
else if (window.cordova.platformId === "browser")
252-
window.location.href = window.location.href.substr(0,
253-
window.location.href.lastIndexOf("/") + 1) +
254-
"#" + (goToPage !== this.state.homePageKey ? goToPage : "");
257+
}
255258

256259

257260
//----navigator and animation----///
@@ -300,7 +303,7 @@ export default class Navigator extends React.Component {
300303

301304
componentWillMount() {
302305
const fthis = this;
303-
if (fthis.state.mobileMode) {
306+
if (!fthis.state.changeRoute) {
304307

305308
// //---lock portrait
306309
// window.screen.orientation.lock('portrait');
@@ -359,7 +362,6 @@ export default class Navigator extends React.Component {
359362
? this.props.children.map(child => {
360363
return <div
361364
onTouchStart={(e) => {
362-
363365
if (child.props.backOnSwipeRight) {
364366
if (e.touches[0].clientX < (0.20 * innerWidth)) {
365367
fthis.touchBackPage = nowPage;

0 commit comments

Comments
 (0)