i have propably problem with this.nav.push in Ionic. I have done a login/registration page but when i login i get this error message. I have to add code from login.ts and e.g home.ts(which is main page) ?
Runtime Error
Uncaught (in promise): invalid link: HomePage
Error: Uncaught (in promise): invalid link: HomePage at d (http://localhost:8100/build/polyfills.js:3:3991) at l (http://localhost:8100/build/polyfills.js:3:3244) at Object.reject (http://localhost:8100/build/polyfills.js:3:2600) at NavControllerBase._fireError (http://localhost:8100/build/main.js:45465:16) at NavControllerBase._failed (http://localhost:8100/build/main.js:45453:14) at http://localhost:8100/build/main.js:45508:59 at t.invoke (http://localhost:8100/build/polyfills.js:3:11562) at Object.onInvoke (http://localhost:8100/build/main.js:4622:37) at t.invoke (http://localhost:8100/build/polyfills.js:3:11502) at n.run (http://localhost:8100/build/polyfills.js:3:6468) at http://localhost:8100/build/polyfills.js:3:3767 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12256) at Object.onInvokeTask (http://localhost:8100/build/main.js:4613:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:12177) at n.runTask (http://localhost:8100/build/polyfills.js:3:7153)
@edit: The problem occurs when I want login to my app. It's code respondent to login.
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 ( here is public function which execute my loin and where i have pass and email which I need to type in login )
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();
});
}
}
I don't know why this code is wrong. My home page iny my app is home.ts and class is HomePage
what you need to do is to add @IonicPage() before '@Component' and import 'IonicPage' like this :
import {NavController, IonicPage} from 'ionic-angular';
then you need to create a module for the homepage i.e in the home directory , create home.module.ts with the following contents
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 {}
and reload the project
The only problem in your code is when you write
this.nav.push('HomePage'); remove the ' ' quotes when calling any page, and write like this.
this.nav.push(HomePage); without quotes.
Above answer is for ionic2, in ionic3 there is lazy loading where you call like this
this.nav.push('HomePage');
I copied login example. The error is similar.
Check points for HomePage : (1) check whether home.module.ts is (2) check @IonicPage() before '@Component' in home.ts (2) remove HomePage from declaration/entryComponents in app.module.ts when facing open-error
Just add @IonicPage() before @component in ts file for example:
@IonicPage() @Component({ selector: 'page-wall', templateUrl: 'wall.html', })
来源:https://stackoverflow.com/questions/43969482/ionic-uncaught-in-promise-invalid-link