Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular CustomReuseStategy在shouldReuseRoute实现中将webpack用于生产模式时未打印正确的组件名称_Angular_Angular Ui Router_Angular2 Router - Fatal编程技术网

Angular CustomReuseStategy在shouldReuseRoute实现中将webpack用于生产模式时未打印正确的组件名称

Angular CustomReuseStategy在shouldReuseRoute实现中将webpack用于生产模式时未打印正确的组件名称,angular,angular-ui-router,angular2-router,Angular,Angular Ui Router,Angular2 Router,我正在使用CustomReuseStragy,并且是指 为了实现shouldReuseRoute,我使用了概述的概念: shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean { let name = future.component && (<any>future.component).name; return super.shou

我正在使用CustomReuseStragy,并且是指

为了实现shouldReuseRoute,我使用了概述的概念:

shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
    let name = future.component && (<any>future.component).name;
    return super.shouldReuseRoute(future, curr) && name !== 'DetailSameComponent';
  }
shouldReuseRoute(未来:ActivatedRouteSnapshot,当前:ActivatedRouteSnapshot):布尔值{
让name=future.component&(future.component).name;
返回super.shouldReuseRoute(future,curr)和&name!=“DetailSameComponent”;
}
这在开发环境中非常有效,但是在生产环境中,组件名称不能正确打印。当我说生产环境时,我指的是这样的情况,当我使用网页包构建客户机并将构建复制到服务器并运行时。在这种情况下,所有组件名称都打印为字母“t”


为什么打印为“t”?它在做网页压缩吗?使用webpack时如何获得正确的组件名称?如果我无法使用webpack获得正确的组件名称,我还可以如何修改此条件,以便根据组件决定是否重新运行?

遵循此指南也让我陷入了一段时间,但这样做似乎可以解决我的问题。它只打印“t”的原因是angular缩小了javascript,以便在通过网络传输时大幅减少捆绑包的大小。唯一的问题是,这似乎也改变了类名,所以依赖于类名的东西将不再起作用。解决办法就是这样

而不是使用

shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
    let name = future.component && (<any>future.component).name;
    return super.shouldReuseRoute(future, curr) && name !== 'DetailSameComponent';
}
它使用对组件本身的引用

TLDR: 将名称='ComponentNameAsText'交换到future.component=组件

import DetailSameComponent from {...}

shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
    return super.shouldReuseRoute(future, curr) && future.component !== DetailSameComponent;
}