我是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 回答
而不是
redirect
,在那里加载component
. 所以你必须用component: SignInComponent
替换redirectTo: "/signIn"
.看到这个小DEMO
注意:你也不应该重定向到同一条路线,它会变成递归的 . 最后,angular将找不到任何可能导致加载的组件