Different routes for landing page and dashboard in Angular2

≯℡__Kan透↙ 提交于 2019-12-23 04:45:11

问题


I am developing a blog site with Angular 2. Now I want to show a signup/login form on landing page when user visit my site only signup form will show no menu or header.

Now when user logged in they will redirect to /dashboard and see the menus and header and content

Now how to start. Is it possible to use two router-outlets?

Signup layout image: http://prntscr.com/dwh1qg

Dashboard layout : http://prntscr.com/dwh2lp


回答1:


Each component can contain router-outlet.

I think that you should create App component which would contain routes to Dashboard component and Default component. In those components you should also put router-outlet and create different routes.

This way you can have different templates for each group of components.

@RouteConfig([
   { path: '/dahsboard/...', name: 'Dashboard', component: DashboardComponent },
   { path: '/...', name: 'Default', component: DefaultComponent }
])
export class AppComponent 

Your template for this component can be as simple as <router-outlet></router-outlet>.

Then your child components can have different routing and different templates.

@RouteConfig([
   { path: '/home', name: 'Home', component: HomeComponent },
   { path: '/sign-up', name: 'SignUp', component: SignupComponent }
])
export class DefaultComponent 

And it's template should also contain <router-outlet></router-outlet>.



来源:https://stackoverflow.com/questions/41684290/different-routes-for-landing-page-and-dashboard-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!