【问题标题】:Ionic Uncaught (in promise): invalid linkIonic Uncaught(承诺):无效链接
【发布时间】:2017-10-13 15:32:46
【问题描述】:

Ionic 中的this.nav.push 可能有问题。我已经完成了登录/注册页面,但是当我登录时,我收到此错误消息。我必须在 login.ts 中添加一些代码,例如 home.ts(这是主页)?

运行时错误
未捕获(承诺):无效链接:主页


错误:未捕获(承诺):无效链接:主页 在 d (http://localhost:8100/build/polyfills.js:3:3991) 在 l (http://localhost:8100/build/polyfills.js:3:3244) 在 Object.reject (http://localhost:8100/build/polyfills.js:3:2600) 在 NavControllerBase._fireError (http://localhost:8100/build/main.js:45465:16) 在 NavControllerBase._failed (http://localhost:8100/build/main.js:45453:14) 在http://localhost:8100/build/main.js:45508:59 在 t.invoke (http://localhost:8100/build/polyfills.js:3:11562) 在 Object.onInvoke (http://localhost:8100/build/main.js:4622:37) 在 t.invoke (http://localhost:8100/build/polyfills.js:3:11502) 在 n.run (http://localhost:8100/build/polyfills.js:3:6468) 在http://localhost:8100/build/polyfills.js:3:3767 在 t.invokeTask (http://localhost:8100/build/polyfills.js:3:12256) 在 Object.onInvokeTask (http://localhost:8100/build/main.js:4613:37) 在 t.invokeTask (http://localhost:8100/build/polyfills.js:3:12177) 在 n.runTask (http://localhost:8100/build/polyfills.js:3:7153)

@edit:当我想登录我的应用程序时会出现问题。这是登录代码。

login.ts

public login() {
    this.showLoading()
    this.auth.login(this.registerCredentials).subscribe(allowed => {
      if (allowed) {        
       this.nav.push('HomePage');
      } else {
        this.showError("Access Denied");
      }
    },
      error => {
        this.showError(error);
      });
    }

auth-service.ts(这里是执行我的登录的公共函数,我有密码和电子邮件,我需要输入登录信息)

  public login(credentials) {
    if (credentials.email === null || credentials.password === null) {
      return Observable.throw("Please insert credentials");
    } else {
      return Observable.create(observer => {
        // At this point make a request to your backend to make a real check!
        let access = (credentials.password === "pass" && credentials.email === "email");
        this.currentUser = new User('Simon', 'saimon@devdactic.com');
        observer.next(access);
        observer.complete();
      });
    }
  }

我不知道为什么这段代码是错误的。我的应用程序中的主页是 home.ts,类是 HomePage

【问题讨论】:

标签: ionic3


【解决方案1】:

你需要做的是在'@Component'之前添加@IonicPage()并像这样导入'IonicPage': import {NavController, IonicPage} from 'ionic-angular';

然后您需要为主页创建一个模块,即在主目录中,使用以下内容创建 home.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './home';

@NgModule({
  declarations: [
    HomePage
  ],
  imports: [
    IonicPageModule.forChild(HomePage),
  ],
  exports: [
    HomePage
  ]
})
export class HomePageModule {}

并重新加载项目

【讨论】:

  • 我做了你所有的建议,但仍然是同样的错误!
【解决方案2】:

你的代码中唯一的问题是你写的时候 this.nav.push('HomePage');调用任意页面时去掉''引号,这样写。

this.nav.push(HomePage); 不带引号。

以上答案适用于 ionic2,在 ionic3 中有延迟加载 像这样打电话this.nav.push('HomePage');

【讨论】:

【解决方案3】:

事实证明,一旦您再次重新启动服务器,它就像一个魅力,我花了几个小时来修复,如果 @IonicPage() 没有解决问题,只需重新启动您的服务器。即ionic serve。 编码愉快!!!

【讨论】:

    【解决方案4】:

    只需在 ts 文件中的 @component 之前添加 @IonicPage() 例如:

    @IonicPage() @零件({ 选择器:'页面墙', templateUrl: 'wall.html', })

    【讨论】:

      【解决方案5】:

      我复制了登录示例。错误类似。

      主页检查点: (1)检查home.module.ts是否为 (2) 在 home.ts 中的 '@Component' 之前检查 @IonicPage() (2) 遇到open-error时从app.module.ts中的declaration/entryComponents中移除HomePage

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-08-18
        • 2021-04-17
        • 1970-01-01
        • 2019-04-17
        • 2018-06-06
        • 1970-01-01
        • 2015-04-15
        • 2023-01-27
        相关资源
        最近更新 更多