Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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 Typescript如何在常量变量中引用类的静态属性_Angular_Typescript - Fatal编程技术网

Angular Typescript如何在常量变量中引用类的静态属性

Angular Typescript如何在常量变量中引用类的静态属性,angular,typescript,Angular,Typescript,我正在处理一个奇怪的情况,至少对我来说是这样。在angular 2项目中,在typescript模块中,我尝试替换如下所示的硬编码路由: const routes: Routes = [ { path: '', redirectTo: 'login', pathMatch: 'full' }, { path: 'login', component: LoginComponent, canActivate: [AuthGuardLogin] }, { path: 'landing', com

我正在处理一个奇怪的情况,至少对我来说是这样。在angular 2项目中,在typescript模块中,我尝试替换如下所示的硬编码路由:

const routes: Routes = [
 { path: '', redirectTo: 'login', pathMatch: 'full' },
 { path: 'login', component: LoginComponent, canActivate: [AuthGuardLogin] },
 { path: 'landing', component: LandingComponent, canActivate: [AuthGuardService] }
];
通过这种方法:

const routes: Routes = [
 { path: RootUris.Base, redirectTo: RootUris.Login, pathMatch: 'full' },
 { path: RootUris.Login, component: LoginComponent, canActivate: [AuthGuardLogin] },
 { path: RootUris.Landing, component: LandingComponent, canActivate: [AuthGuardService] }
];
其中RootUris是这样一个类:

export class RootUris {
    public static readonly Base: string = '';
    public static readonly Login: string = 'login';
    public static readonly Landing: string = 'landing';
}
当我在dev中工作时,一切都进行得很顺利,即使我运行应用程序,它也可以正常工作,但是当我尝试使用ng build--prod构建它时,我得到了以下结果:

处于非法状态时出错:应为没有成员的符号,但得到了{“filePath”:“C:/dev/myApp/client/src/app/common/url mapping.ts”,“name”:“RootUris”,“members”:[“Base”]}

./src/main.ts中出现错误 未找到模块:错误:无法解析“C:\repo\Behavior health legend\client\src”中的“/$$\u gendir/app/app.Module.ngfactory” @./src/main.ts 4:0-74 @multi./src/main.ts

这里最罕见的是,如果替换数组的第一个元素(仅此而已,其余元素仍使用静态属性):

通过这个:

{ path: '', redirectTo: 'login', pathMatch: 'full' }
一切正常


那么,有人知道为什么我不能在那里(数组的第一个元素中)使用类的static属性吗?有什么想法吗?

阵列中的第一个也是唯一一个具有pathMatch的,您可以尝试删除它,但保留静态变量,看看是否有效吗?只是想把问题孤立起来。非常确定pathMatch需要一个字符串而不是表达式。感谢您的回复,我刚刚尝试了您之前提到的方法:
{Path:RootUris.Base,redirectTo:RootUris.Login}
从这个意义上讲,它甚至在开发中都不起作用,我得到了以下结果:错误:路由{Path:,redirectTo:Login}的配置无效“:请提供“路径匹配”。“pathMatch”的默认值为“prefix”,但其目的通常是使用“full”。
{ path: '', redirectTo: 'login', pathMatch: 'full' }