2017-05-26 103 views
0

我在我的应用程序上有一条名为home的路线,并且上面有一些内容。问题是这个内容没有被显示,它只显示在app.component的菜单。我觉得我错过了一些愚蠢的东西,有人能帮助我吗?这是代码:路由内容未显示

这是Home.component:

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

    @Component({ 
     moduleId: module.id, 
     selector: 'home', 
     templateUrl: `home.component.html` 
    }) 

    export class HomeComponent{} 

App.routing.ts:

import {ModuleWithProviders} from '@angular/core'; 
import {Routes, RouterModule} from '@angular/router'; 
import {HomeComponent} from './home.component' 


const appRoutes: Routes = [ 
    { 
     path:'', 
     redirectTo: '/', 
     pathMatch: 'full' 
    }, 
    { 
     path: 'home', 
     component: HomeComponent 
    }, 
] 

export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes); 

app.module.ts:

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 

import { AppComponent } from './app.component'; 
import {HomeComponent} from './home.component'; 

@NgModule({ 
    imports:  [ BrowserModule ], 
    declarations: [ AppComponent, HomeComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

和孤单index.html:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>Angular QuickStart</title> 
    <base href="/"> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="styles.css"> 
    <link rel="stylesheet" href="css/meu-css.css"> 
    <link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/> 
    <!-- Polyfill(s) for older browsers --> 
    <script src="node_modules/core-js/client/shim.min.js"></script> 

    <script src="node_modules/zone.js/dist/zone.js"></script> 
    <script src="node_modules/systemjs/dist/system.src.js"></script> 

    <script src="systemjs.config.js"></script> 
    <script> 
     System.import('main.js').catch(function(err){ console.error(err); }); 
    </script> 
    </head> 

    <body> 
    <base href="/"> 
    <my-app>Loading AppComponent content here ...</my-app> 
    </body> 
</html> 

回答

1

我需要看到你的app.component是一定的,但如果我不得不作出一个猜测,我会说,你可能没有

<router-outlet></router-outlet> 

在模板中为您app.component。 router-outlet通知路由器在哪里绘制由路径确定的组件。