我正在尝试将angular2应用程序从已弃用的路由器切换到推荐的路由器[https://angular.io/docs/ts/latest/guide/router.html][1].I,并在angular2 cli的帮助下构建我的项目。我已经成功完成了没有cli的种子项目,但是当使用cli执行此操作时,我不断收到此错误:
将http://localhost:4200/app.routes加载为“./app.routes”时出错 http://localhost:4200/main.js“;区域:;任务:承诺。然后; 值:错误: patchProperty/desc.set/wrapFn@http://localhost:4200/vendor/zone.js/dist/zone.js:769:27 Zonehttp://本地主机:4200 /供应商/ zone.js / DIST / zone.js:356:24 Zonehttp://本地主机:4200 /供应商/ zone.js / DIST / zone.js:256:29 ZoneTask/this.invoke@http://localhost:4200/vendor/zone.js/dist/zone.js:423:29 加载http://localhost:4200/app.routes为“./app.routes”时出错 来自http://localhost:4200/main.js
这是我的main.ts文件。
import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppComponent, environment } from './app/';
import { APP_ROUTER_PROVIDERS } from './app.routes';
if (environment.production) {
enableProdMode();
}
bootstrap(AppComponent, [APP_ROUTER_PROVIDERS])
.catch(err => console.error(err));
这是我的app.routes.ts文件
import { provideRouter, RouterConfig } from '@angular/router';
import {Main} from "./app/splash_app/main.component";
import {Whatsup} from "./app/splash_app/whatsup.component";
import {LocalBus} from "./app/splash_app/localbus.component";
import {Login} from "./app/splash_app/login.component";
export const routes: RouterConfig = [
{ path: 'main', component: Main },
{ path: 'search', component: Whatsup },
{ path: 'local-business', component: LocalBus },
{path: 'guest-login', component: Login}
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
这是system-config文件
// SystemJS configuration file, see links for more information
// https://github.com/systemjs/systemjs
// https://github.com/systemjs/systemjs/blob/master/docs/config-api.md
/***********************************************************************************************
* User Configuration.
**********************************************************************************************/
/** Map relative paths to URLs. */
const map: any = {
};
/** User packages configuration. */
const packages: any = {
};
////////////////////////////////////////////////////////////////////////////////////////////////
/***********************************************************************************************
* Everything underneath this line is managed by the CLI.
**********************************************************************************************/
const barrels: string[] = [
// Angular specific barrels.
'@angular/core',
'@angular/common',
'@angular/compiler',
'@angular/http',
'@angular/router',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
// Thirdparty barrels.
'rxjs',
// App specific barrels.
'app',
'app/shared',
/** @cli-barrel */
];
const cliSystemConfigPackages: any = {};
barrels.forEach((barrelName: string) => {
cliSystemConfigPackages[barrelName] = { main: 'index' };
});
/** Type declaration for ambient System. */
declare var System: any;
// Apply the CLI SystemJS configuration.
System.config({
map: {
'@angular': 'vendor/@angular',
'rxjs': 'vendor/rxjs',
'main': 'main.js'
},
packages: cliSystemConfigPackages
});
// Apply the user's configuration.
System.config({ map, packages });
main.ts文件和app.routes.ts文件都在src文件夹中。
答案 0 :(得分:0)
将app.routes.ts
文件移至app
目录,然后在main.ts
内更改导入以指向新路径....
import { APP_ROUTER_PROVIDERS } from './app/app.routes';