Page has a @IonicPage decorator, but it does not have a corresponding “NgModule”

后端 未结 11 2478
花落未央
花落未央 2020-12-16 11:06

I was working on page navigation in Ionic. After using ionic serve, I got this error:

The Page with .ts extension has a @IonicPage decorator, but

相关标签:
11条回答
  • 2020-12-16 11:43

    This is because @IonicPage() decorator is utilized for deep linking and lazy loading, so to implement that, you need a dedicated module to load all the required components for that page. Take a look at the Ionic docs:

    @IonicPage API docs

    0 讨论(0)
  • 2020-12-16 11:48

    This issue may occurs when you're using angular 2+ naming conventions, where it's used to be like my-app.component.ts, updating to the ionic 3 naming convention my-app.ts, you'll be able to use the @IonicPage() decorator if you need it.

    0 讨论(0)
  • 2020-12-16 11:48

    In your .ts page add the following code, replace the word 'name' with whatever you name your page. Don't forget to add your new page in the app.module.ts page.

    import { Component } from '@angular/core';
    import { NavController } from 'ionic-angular';
    
    @Component({
    selector: 'page-name',
    templateUrl: 'name.html',
    })
    
    export class NamePage {
       constructor(public navCtrl: NavController) {
      }
    }
    
    0 讨论(0)
  • 2020-12-16 11:49

    When you add a page using Ionic CLI for example

    ionic generate page newPage

    then it automatically generates file newPage.module.ts and inside newPage.ts it generates a line of text as

    @IonicPage()

    Well, you must delete newPage.module.ts and delete @IonicPage() from newPage.ts

    then open app.module.ts and add newPage inside declarations and entry components.

    0 讨论(0)
  • 2020-12-16 11:49

    Today I had the same issue when generating a page. This didn't happen a few days ago.

    I deleted the page's NgModule and then the @IonicPage() decorator, which restored functionality. A bit hacky, but it's up and running for now...

    0 讨论(0)
  • 2020-12-16 11:54

    I just removed the following attribute from the component page:

    <!-- /src/app/pages/{page-name}/{page-name.ts} -->
    @IonicPage()
    

    Other ionic example pages don't even have it. Seems like the ionic CLI is outdated (I'm guessing you used that to generate the page component).

    0 讨论(0)
提交回复
热议问题