Search code examples
javascriptandroidcordovaroutespage.js

Phonegap with page.js routes works only on desktop


I am using page.js in an HTML+CSS+JS app.

The routes work perfectly in browser, even using the "phonegap serve" and accessing my_ip:3000.

But when I try to load it in my phoneGap Developer (in an Android phone), only the first route loads (if I try to navigate through the app links, I get only blank screens).


Solution

  • When using page.js in mobile apps (with cordova, phonegap or cocoon), just use:

    page( { dispatch: false } )
    page( '/' )
    

    Instead of:

    page()
    

    You can replace '/' with the first route that you want your app to start with.


    In details:

    Normally, in a web app, you use page() to start the routing process and, of course, it will identify which route is being requested and call the correspondent function.

    Since in mobile we don't have an URL request, we disable this identification process with dispatch: false and pass a default start route.