Pages declaration


How can I import, declare and push a page I already used somewhere else?

Suppose I have 2 pages:
1st page is HomePage (can call 2nd page)
2nd is called by HomePage and it can call 1st page

A sort of circular dependency. When I import 1st page in 2nd page.module I get an error since NgModule of 2nd page cause problems with app.module 's NgModule since both have a declaration of the same page but if I don’t do it I get an error.


There are two answers to this question, and I can’t tell which is right for your situation because I am hearing conflicting things about your use of lazy loading.

If you are lazy loading pages, then the answer is “don’t import anything anywhere and just pass strings to the navigation controller”.

If you aren’t, then the answer is “delete all @IonicPage decorators and page modules, put both pages in the app module, and then simply import freely”.

Incidentally, I think circular dependencies like this are often a design flaw. Page2 should not need to know about Page1; it should only know to pop() and send the user back to whereever it was spawned from. If Page2 pushes HomePage, and then HomePage pushes Page2 again, you get a really confusing navigation stack for the user.