具有嵌套状态的 Angular2 路由

Angular2 routing with nested states

我有一个登录页面,它将向用户显示(默认情况下)和 "Sign Up" 组件,这是一组允许他们注册的输入字段。

对于返回的用户,我希望他们按原样看到登录页面,然后单击 "Log In" 并将注册组件替换为登录组件。我不希望 URL 改变,它应该保持为 '/'。

对于 ui-router,我可以做嵌套状态,但不确定 Angular2 的路由器是否支持它?

app.ts

@Component({
  selector: 'app',
  template: '
    *snip*
    <router-outlet></router-outlet>
    *snip*
  ',
  directives: [Footer, ROUTER_DIRECTIVES]
})
@RouteConfig([
  { path: '/...', name: 'Landing', component: LandingComponent, useAsDefault: true },
  { path: '/about', name 'About', component: AboutComponent }
]);

landing.ts

@Component({
  selector: 'landing',
  template: '
    <body>
      <div>
        <router-outlet></router-outlet>
      </div>
    </body>',
  directives: [ROUTER_DIRECTIVES]

})
@RouteConfig([
  { path: '/', name: 'RegisterForm', component: RegisterForm, useAsDefault: true },
  { path: '/login', name: 'LoginForm', component: LoginForm },
])

登陆组件的路径是否需要不同?

那你为什么需要使用路由呢?不能只绑定到一个隐藏或显示相应部分的布尔值吗?

<div *ngIf="showReg">Registration</div>

<div *ngIf="!showReg">Login</div>