Skip to content

Navigation trade off #12402

@AmitMY

Description

@AmitMY

Ionic version: (check one with "x")
[ ] 1.x (For Ionic 1.x issues, please use https://github.com/ionic-team/ionic-v1)
[ ] 2.x
[x] 3.x

I'm submitting a ... (check one with "x")
[ ] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:
Having an app with navigation guards (ionViewCanEnter), and URL segments, does not allow a fallback for page evaluation.

Having an app with authentication, lets say I have 3 pages:

page/link guard
login isGuest : Promise
home isAuthenticated: Promise
other isAuthenticated: Promise

If I don't set rootPage, nothing happens by default, so I have to set it, and the only choice is login

Now if I go to /home, I see a blank page, because it tried to load the home page, but the user is not authenticated. User must go to either / or /login.

After the user is authenticated, now when he goes to /home, everything is fine, but if by accident he pressed on a link of /login, there is a blank page (can't enter, so nothing)

Finally, one would say: Check if the user is authenticated. if they are, set rootPage to home, and if not to login.

But what if the user (authenticated) goes to /other? they are immediately redirected to home. A possible suggestion would be to check the active page, but because of the nav guard, there is no active page before we know if the user is authenticated, so must also add a timeout for it to happen asyncronically.

Note: this does not happen only with authentication, even with sequential nav guards, like checking if page got all parameters.

Expected behavior:
I think there should be an option to bind a function to the nav, like onCantEnter or something, that fires only if the first page it tries to load can not be entered. It would get the component it tried to load, and let the user do whatever with that information, for example:

this.nav.onCantEnter((page) => {
  if(UNAUTHENTICATED_PAGES.indexOf(page.name) > -1)
    this.nav.setRoot('HomePage');
  else 
    this.nav.setRoot('LoginPage')
});

Note: I din't find where in the code it does that first load and executes ionViewCanEnter, so I can't create a PR.

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

global packages:

    @ionic/cli-utils : 1.5.0
    Cordova CLI      : 7.0.1
    Ionic CLI        : 3.5.0

local packages:

    @ionic/app-scripts              : 2.0.2
    @ionic/cli-plugin-cordova       : 1.4.1
    @ionic/cli-plugin-ionic-angular : 1.3.2
    Cordova Platforms               : browser 4.1.0
    Ionic Framework                 : ionic-angular 3.5.2

System:

    Node       : v8.1.2
    OS         : Windows 10
    Xcode      : not installed
    ios-deploy : not installed
    ios-sim    : not installed
    npm        : 5.0.3 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions