我有一个登录页面,它将显示用户(默认情况下)和“注册”组件,该组件是一组允许他们进行注册的输入字段。

对于回访用户,我希望他们按原样查看登录页面,然后单击“登录”并将注册组件替换为登录组件。我不希望 URL 更改,它应该保留为“/”。

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

应用程序

@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 }
]);

登陆.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 },
])

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

最佳答案

为什么你需要使用路线呢?你不能只绑定(bind)到一个隐藏或显示适当部分的 bool 值吗?

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

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

关于具有嵌套状态的 Angular2 路由,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34568594/

10-12 16:23
查看更多