Angular 2 - 模块在刷新时加载两次

时间:2016-06-14 13:24:03

标签: angular typescript routing refresh

我有ab Angular 2 app。使用路由器已弃用(因为新路由器目前尚未记录)。有两条基本路线(家庭和管理员)。 如果我加载应用程序或执行F5刷新,则会加载当前模块两次(您可以看到html文件被请求两次,构造函数也被调用两次。如何阻止应用程序加载路径两次?更改路径不会导致"双重加载"。只有F5 / frist加载

<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 :(得分:1)

已关闭:已在index.html中添加了两次externallibs.js(一个是手动,一个是通过webpack)....