-
Notifications
You must be signed in to change notification settings - Fork 186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs for routing to internal page based on location.hash #828
base: 7.x-1.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
The default behavior for DrupalGap is to direct to the front page set in the `settings.js` file. This breaks the sharing feature that users are used to on a typical web site. This code may be added to `settings.js` to enable direction to internal pages. | ||
|
||
**This method has only been tested in a web app.** | ||
|
||
``` | ||
var landingPage = 'dashboard'; | ||
if(location.hash){ | ||
// additional logic can be added here for other internal page types and exclude certain pages from being directed to on the initial app load. | ||
goToPage = location.hash.replace("#",""); | ||
landingPage = goToPage.replace('node_', 'node/'); | ||
} | ||
|
||
// fix drupalgap_back() to not break if coming from external page | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattshoaf Thank you for sharing this workaround. I'd be hesitant to add this to the docs, overwriting DG core isn't my favorite. But you've come up with a clever idea above, I'd like to extract it and make it possible for DG core to route to an internal page (not just the front page). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was some concern with pull request 787 that this change might break the back button for an app ported through PhoneGap. I'm thinking that this solution only works for web apps, in a native app you'll have to parse data from a notification to set a dynamic front page. Notice that I hardcoded the page on line 28 of this code. If it's added to the core, it will probably need to have another variable set there, something like this maybe? Starting on line 27 of this code:
And require that |
||
function drupalgap_back() { | ||
try { | ||
var active_page_id = $('.ui-page-active').attr('id'); | ||
if (active_page_id == drupalgap.settings.front) { | ||
var msg = t('Exit') + ' ' + drupalgap.settings.title + '?'; | ||
if (drupalgap.settings.exit_message) { | ||
msg = drupalgap.settings.exit_message; | ||
} | ||
drupalgap_confirm(msg, { | ||
confirmCallback: _drupalgap_back_exit | ||
}); | ||
} | ||
else if (active_page_id == '_drupalgap_splash') { return; } | ||
else if (drupalgap.back_path == ''){ | ||
drupalgap_goto('dashboard'); | ||
return; | ||
} | ||
else { _drupalgap_back(); } | ||
} | ||
catch (error) { console.log('drupalgap_back' + error); } | ||
} | ||
|
||
``` | ||
Change line 120 `drupalgap.settings.front = 'dashboard';` to `drupalgap.settings.front = landingPage;` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattshoaf What line 120 is this referring to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 120 in the default.settings.js file. To change the front to a dynamic page, you have to set it as a variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattshoaf So this part works for redirecting to node pages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the regex changes the format from the hash value to what the DrupalGap page navigation is expecting for a node page.