Ionic 3 Component vs Page

前端 未结 2 1724
你的背包
你的背包 2021-01-30 08:08

Can you tell me what is the difference between Component and Page generator in the Ionic 3 app? It seems I can use page life cycle hooks l

2条回答
  •  时光说笑
    2021-01-30 09:08

    There are two separate generators because one extra decorator that was added to ionic: @IonicPage

    This decorator gives a few advantages over a simple component.

    1. Routing - you can signify what is the url of the page, how to get there and what is its default history. With this you can access any page directly without going through the navigation path. The routing to this page can also be done with a string rather than the actual component

    2. Lazy loading - the module of a page that has this decorator will be lazy loaded by default when going to the url of the page.

    3. No app module reliance - this is more of a personal favorite but when you create modules that are pages you don't have to add them to your original ngModule and this is done automatically on compilation.

    For more documentation: https://ionicframework.com/docs/api/navigation/IonicPage/

提交回复
热议问题