Skip to content
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

Open
wants to merge 3 commits into
base: 7.x-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/09_Pages/Navigating_Pages/Internal_Page_on_App_Load.md
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';
Copy link
Owner

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?

Copy link
Author

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.

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
Copy link
Owner

Choose a reason for hiding this comment

The 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).

Copy link
Author

@mattshoaf mattshoaf Jul 22, 2016

Choose a reason for hiding this comment

The 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:

else if (drupalgap.back_path == ''){
    drupalgap_goto(drupalgap.settings.default_back);
    return;
}

And require that drupalgap.settings.default_back is set in settings.js

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;`
Copy link
Owner

Choose a reason for hiding this comment

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

@mattshoaf What line 120 is this referring to?

Copy link
Author

Choose a reason for hiding this comment

The 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.