2016-08-15 2 views
2

경로 ''(홈페이지)에서 AppComponent의 html이 두 번로드됩니다.경로 '/'에서 AppComponent html이 두 번로드됩니다.

main.ts

import { bootstrap } from '@angular/platform-browser-dynamic'; 
import { enableProdMode, NgModule } from '@angular/core'; 
import { AppComponent } from './app/components/app/app.component'; 
import { APP_ROUTER_PROVIDERS } from './app/components/app/app.routing'; 

if (true) { 
    enableProdMode(); 
} 

bootstrap(AppComponent, [APP_ROUTER_PROVIDERS]); 

import { Routes, RouterModule, provideRouter } from '@angular/router'; 
import { AuthComponent } from "../auth/auth.component"; 
import { AppComponent } from "./app.component" 

const appRoutes: Routes = [ 
    { 
    path: 'auth', 
    component: AuthComponent 
    }, 
    { 
    path: '', 
    component: AppComponent 
    } 
]; 

export const APP_ROUTER_PROVIDERS = [provideRouter(appRoutes)]; 

app.component.ts

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

@Component({ 
    selector: 'app-component', 
    templateUrl : './app/components/app/app.component.html' 
}) 

export class AppComponent{ 

} 

내 index.html 파일을 app.routing.ts

<!doctype html> 
<html> 
<head> 
    <base href="/"> 
    <meta charset="utf-8"> 

    {{#unless environment.production}} 
    <script src="/ember-cli-live-reload.js" type="text/javascript"></script> 
    {{/unless}} 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="icon" type="image/x-icon" href="favicon.ico"> 
</head> 
<body> 
    <app-component>Loading</app-component> 


    {{#each scripts.polyfills}} 
    <script src="{{.}}"></script> 
    {{/each}} 
    <script> 
     System.import('system-config.js').then(function() { 
     System.import('main'); 
     }).catch(console.error.bind(console)); 
    </script> 

</body> 
</html> 
,

은 내가 '테이블 HTML 번로드 라우팅에서하지만 난 예외를 얻을 :

Uncaught (in promise): Error: Cannot match any routes: ''

+0

'useAsDefault : true'를'path : '''에 추가하려고 시도 했습니까? – Sanket

답변

4

당신은 AppComponent 부트 스트랩하고 "기본"으로 데를'경로를 제거하는 경우뿐만 아니라 ('/') 경로를. 일반적으로 부트 스트랩 된 구성 요소에는 "마스터 페이지"(웹 페이지의 일정 부분)가 포함되어 있으며 경로에 정의 된 경로는 router outlet으로 이동합니다. 따라서 부트 스트래핑에 다른 구성 요소를 사용하는 경우 예상대로 작동해야합니다.

+0

어 어떻게 작동하는지 알 수 있습니다. – Sefa