NativeScript无法匹配任何路由

时间:2018-07-09 17:52:20

标签: angular routing nativescript

我是Angular和NativeScript的超级新手,无法真正弄清楚如何完成整个路由工作。目前,我在说

时遇到错误
  

错误:无法匹配任何路由。网址段:“ signIn”

这是.html home.component.html,我的按钮是:

			<Button class="btn btn-primary btn-rounded-sm" style="width: 90%; height: 7%; padding: 0px; margin: 5px; background-color: black; color: white; vertical-align: bottom;" text="Sign pIn" (tap)=onSignIn()></Button>

这是home.component.ts组件,其功能是:

onSignIn(): void { 
    this.router.navigate(['signIn']);
}

然后是我的signIn.component.ts

import { Component, OnInit } from "@angular/core";

@Component({
    selector: "SignIn",
    moduleId: module.id,
    templateUrl: "./signIn.component.html",
    styleUrls: ['./signIn.component.css']
})
export class SignInComponent implements OnInit { }

此外,这是在app-routing.module.ts中配置我的路由的地方:

{ path: "signIn", redirectTo: "/signIn", pathMatch: "full" }

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:2)

redirect加载到那里,而不是component。因此,您必须将redirectTo: "/signIn"替换为component: SignInComponent

const routes: Routes = [
  { path: "signIn", component: SignInComponent, pathMatch: "full" }
];

看到这个小的DEMO

注意:而且您也不应重定向到同一路由,否则它将变为递归。最后,角度不会找到任何可能导致

加载的分量
  

无法匹配任何路由错误

相关问题