Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
[navigation] Handle the case where the initial URL contains a non-pat…
Browse files Browse the repository at this point in the history
…h hash that points to a non-existing page
  • Loading branch information
Gabriel Schulhof committed Jul 26, 2012
1 parent 67b9ac1 commit 207f854
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions js/jquery.mobile.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ define( [ "jquery", "./jquery.mobile.core", "./jquery.mobile.support", "./jquery
$.mobile.path.isHashValid( location.hash ) &&
( $( location.hash + ':jqmData(role="page")' ).length ||
$.mobile.path.isPath( location.hash ) ) ) ) {

// Store the initial destination
if ( $.mobile.path.isHashValid( location.hash ) ) {
$.mobile.urlHistory.initialDst = $.mobile.path.parseUrl( location.href ).hash.replace( "#", "" );
}
$.mobile.changePage( $.mobile.firstPage, { transition: "none", reverse: true, changeHash: false, fromHashChange: true } );
}
// otherwise, trigger a hashchange to load a deeplink
Expand Down
8 changes: 8 additions & 0 deletions js/jquery.mobile.navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,14 @@ define( [
// since the hashchange could've been the result of a forward/backward navigation
// that crosses from an external page/dialog to an internal page/dialog.
to = ( typeof to === "string" && !path.isPath( to ) ) ? ( path.makeUrlAbsolute( '#' + to, documentBase ) ) : to;

// If we're about to go to an initial URL that contains a reference to a non-existent
// internal page, go to the first page instead. We know that the initial hash refers to a
// non-existent page, because the initial hash did not end up in the initial urlHistory entry
if ( to === path.makeUrlAbsolute( '#' + urlHistory.initialDst, documentBase ) &&
urlHistory.stack.length && urlHistory.stack[0].url !== urlHistory.initialDst.replace( dialogHashKey, "" ) ) {
to = $.mobile.firstPage;
}
$.mobile.changePage( to, changePageOptions );
} else {
//there's no hash, go to the first page in the dom
Expand Down

1 comment on commit 207f854

@jerone
Copy link
Contributor

@jerone jerone commented on 207f854 Oct 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this was added...
It is causing issues described in this issue #5121

Please sign in to comment.