2016-06-14 11 views
2

私は角2アプリを持っています。 router-deprecatedを使用します(新しいルータは現在文書化されていません)。 2つの基本的なルート(ホームと管理者)を持つ。 アプリケーションをロードするかF5をリフレッシュすると、現在のモジュールが2回読み込まれます(htmlファイルが2回要求され、コンストラクタも2回呼び出されることがわかります)。ルートは "二重のロード" のみF5 /延期負荷角2モジュールがリフレッシュ時に2回ロードされる

<html> 
<head> 
<base href= /> 
<title>Consyd Time Management</title> 
<meta charset=UTF-8> 
<meta name=viewport content="width=device-width,initial-scale=1"> 
<link rel=stylesheet href=public/css/styles.css>  
<link rel=stylesheet href=node_modules/bootstrap/dist/css/bootstrap.min.css> 
<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/reflect-metadata/Reflect.js></script> 
<script src=public/scripts/externalLibs.js></script> 
</head> 
<body> 
<div id=main class=container-fluid> <start-page>Loading...</start-page>  </div> 

start.ts

import { Component } from '@angular/core'; 
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from  '@angular/router-deprecated'; 
import { NavigationMenu } from "./navigation"; 
import { myRoutes } from '../routes'; 


@Component({ 
selector: 'start-page', 
template: ` 
<h2>Startseite</h2> 
<navigation-menu></navigation-menu> 
<router-outlet></router-outlet>`, 
directives: [ROUTER_DIRECTIVES, NavigationMenu] 
}) 
@RouteConfig(myRoutes) 

export class StartPage { 

} 

とroutes.ts

が発生することはありません。
import { RouteDefinition } from '@angular/router-deprecated'; 
import { HomePage } from './views/home'; 
import { AdminPage} from './views/adminpage'; 


export const myRoutes: RouteDefinition[] = [ 
    { 
     path: '/', 
     name: 'Home', 
     component: HomePage 
    }, 
    { 
     path: '/admin', 
     name: 'Admin', 
     component: AdminPage 

    } 
]; 

home.ts休館

//imports going here 
@Component({ 
    selector: 'start-page', 
    templateUrl: 'public/app/html/home.html', 
    directives: [DROPDOWN_DIRECTIVES, CORE_DIRECTIVES], 
    providers: [HttpService] 
}) 

export class HomePage { 
    constructor(private httpService: HttpService) { 
     if (!this.selectedProject) { 
      this.selectedProject = new Project("Projekt auswählen"); 
     } 
     this.getUsers(this.setUser); 

    } 
//REST OF CODE 

答えて

1

は:

+0

.... index.htmlを(手で1とのWebPACKずつ)で二回アイデアをありがとうexternallibs.jsを追加した - 私が追加しました二重負荷の原因となっていたNgModuleのブートストラップアレイへのコンポーネント。それは宣言にあってはならず、ブートストラップにも含まれていなければなりません。 – DFBerry

関連する問題