在Angular2中定义路由时什么都没有

时间:2017-03-01 12:04:18

标签: angularjs routes

我是Angular2的新手。我正在尝试创建给定here的路由。 我创建了三个组件,例如HeaderComponentSidebarComponentUiElementsComponents。所有这些都在main.module文件(根模块)中声明。一切都很好,直到现在。但是当我定义路线时,它停止显示任何东西。即使没有显示任何错误。这是我的代码。

main.module.ts

//Main (root) module of App is defined here.
import { NgModule }             from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { BrowserModule }        from '@angular/platform-browser';
import { MainComponent }        from './../components/main.component';
import { HeaderComponent }      from './../components/header.component';
import { SidebarComponent }     from './../components/sidebar.component';
import { UiElementsComponent }  from './../components/ui-elements.component';


    const routes: Routes = [
                            { path: '', redirectTo: '/test', pathMatch: 'full' },
                            { path: 'test', component: UiElementsComponent},
                        ];
    // The root module of the pratham app.
    @NgModule({
      imports:      [ 
                        BrowserModule,
                        RouterModule.forRoot(routes) 
                    ],
      declarations: [ 
                        MainComponent, 
                        HeaderComponent,
                        SidebarComponent,
                        UiElementsComponent
                    ],
      bootstrap:    [ MainComponent ]
    })

    export class MainModule { }

main.component.ts

//Main (root) component of Pratham is defined here.

import { Component } from '@angular/core';

@Component({
  selector:   'prtm-main',
  template:   `<div class="prtm-wrapper">
                    <prtm-header-section></prtm-header-section>
                    <div class="prtm-main">
                        <prtm-sidebar-section></prtm-sidebar-section>
                        <router-outlet></router-outlet>
                    </div>
               </div>`
})
export class MainComponent  { }

我已经浪费了几个小时才找到问题。你能告诉我我错过了什么吗?

0 个答案:

没有答案