我有AB角2应用程序。不推荐使用路由器(因为新路由器目前没有文档记录)。有两条基本路线(家和管理)。
如果我加载应用程序或执行f5刷新,当前模块将加载两次(您可以看到html文件被请求两次,构造函数也被调用两次)。如何防止应用程序加载两次路由?改变路线不会造成“双重装载”。仅F5/第一次装载
<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>
开始时间
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
}
];
主页.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
最佳答案
关闭:在index.html中添加了externallibs.js两次(一次手动,一次webpack)……
关于angular - Angular 2-刷新时模块加载两次,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37813385/