【发布时间】:2020-03-15 00:44:11
【问题描述】:
使用 ng build --prod 和 ng serve --prod 测试我的应用程序生产版本我在 chrome 上遇到这些错误:
Firefox 在控制台中给出了一些不同的输出:
任何想法可能导致它?我正在运行角度 8。
然后使用简单的 ng serve 测试应用程序看起来一切正常,只有在生产后控制台中没有错误。错误仍然存在,然后应用程序也托管在服务器中。告诉我是否需要提供有关我的应用的更多信息。
这是我的 app.routing.ts 文件:
export const AppRoutes: Routes = [
{
path: '',
component: FrontendPanelLayoutComponent,
loadChildren: () => import('./pages/pages.module').then(mod => mod.PagesModule)
}
];
和 pages.routing.ts:
export const PagesRoutes: Routes = [
{
path: pages.Home,
component: LandingComponent
},
{
path: pages.Products,
component: ProductsComponent
},
{
path: pages.Products + '/:category',
component: ProductsListComponent
},
{
path: pages.Products + '/:category/:product',
component: ProductsViewComponent
},
{
path: pages.Services,
component: ServicesComponent
},
{
path: pages.Services + '/:service',
component: ProductsViewComponent
},
{
path: pages.About,
component: AboutUsComponent
},
{
path: pages.Contacts,
component: ContactsComponent
},
{
path: '',
pathMatch: 'full',
redirectTo: pages.Home
}
];
这是错误的原因,但它在 node_modules router.js 文件中不是我的代码。奇怪为什么这些错误只出现在ng build --prod之后,ng serve没有显示任何问题。
function defaultUrlMatcher(segments, segmentGroup, route) {
var parts = route.path.split('/');
if (parts.length > segments.length) {
// The actual URL is shorter than the config, no match
return null;
}
if (route.pathMatch === 'full' &&
(segmentGroup.hasChildren() || parts.length < segments.length)) {
// The config is longer than the actual URL but we are looking for a full match, return null
return null;
}
var posParams = {};
// Check each config part against the actual URL
for (var index = 0; index < parts.length; index++) {
var part = parts[index];
var segment = segments[index];
var isParameter = part.startsWith(':');
if (isParameter) {
posParams[part.substring(1)] = segment;
}
else if (part !== segment.path) {
// The actual URL part does not match the config, no match
return null;
}
}
return { consumed: segments.slice(0, parts.length), posParams: posParams };
}
【问题讨论】:
-
@GreyBeardedGeek 是的,但是 router.js.pre-build-optimizer 来自节点模块,这是模块本身的问题吗?
-
你好@Cooper。请分享您的应用程序路由文件。那里似乎出了点问题。
-
@DamianC 更新!
-
您可以更改为延迟加载路由的新语法:angular.io/guide/lazy-loading-ngmodules
-
@DamianC 将 app.routing.ts 更新为延迟加载,但错误仍然存在,还有其他想法吗?
标签: angular build prototype production