Search code examples
cordovaionic2hybrid-mobile-app

ionic 2 push notification not working in my custom page?


In my ionic 2 app, I have 2 pages index.html (default loading page) and channel.html (a general page not present in app/pages). I receive push notification when I'm in index.html but I will not receive when I'm in channel.html. Can anyone please suggest me what should I do so that I can get the push notification on both the pages. Thank you in advance.


Solution

  • In ionic 2, it's not a good practice to create a custom loading page it is always good to have index.html as default loading page. The reasons are

    • Index.html acts as the container for all pages that are present in src/pages.

    • As index.html acts as container for all pages any notification will work only in those pages. If you navigate to any other page present in src/custom_page or to some external URL it is not treated as ionic page so push will not work.

    • During ionic build the index.html is built and transferred from src/index.html to www/index.html it will not happen with any of the custom page.

    • If you are bound by your requirement of custom page I suggest take your time and modify the existing code so you can cope-up with index.html as default loading page, because custom loading will trouble your projects in future.