2016-07-07 150 views
0

嘗試做Angular教程時,我遇到了很多試圖做路由器部分的問題。起初我根本無法編譯它,它說它無法找到路由器,導致我嘗試升級到3.0.0 alpha以及其他我無法記住的潛在解決方案。最後,我把它編譯,但是當我嘗試查看網頁,我得到的是默認的「正在加載...」文本無限期和控制檯錯誤在JS控制檯:角度「英雄之旅」教程 - 找不到路由器

localhost/:18 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/router(…)(anonymous function) @ localhost/:18 
http://localhost:3000/node_modules/@angular/router/router.umd.js Failed to load resource: the server responded with a status of 404 (Not Found) 

我的長相的index.html像這樣:

<html> 
<head> 
<base href="/"> 
<title>My lil' tour o' 'roes</title> 
<meta charset="UTF-8"> 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="styles.css"> 
<!-- 1. Load libraries --> 
<!-- Polyfill(s) for older browsers --> 
<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="node_modules/systemjs/dist/system.src.js"></script> 
<!-- 2. Configure SystemJS --> 
<script src="systemjs.config.js"></script> 
<script> 
    System.import('app').catch(function(err){ console.error(err); }); 
    System.import('router').catch(function(err){ console.error(err); }); <!-- LINE 18 --> 
</script> 
</head> 
<!-- 3. Display the application --> 
<body> 
<my-app>Loading...</my-app> 
</body> 
</html> 

而且我的package.json樣子:

{ 
"name": "angular2-quickstart", 
    "version": "1.0.0", 
    "scripts": { 
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ", 
    "lite": "lite-server", 
    "postinstall": "typings install", 
    "tsc": "tsc", 
    "tsc:w": "tsc -w", 
    "typings": "typings" 
    }, 
    "license": "ISC", 
    "dependencies": { 
    "@angular/common": "2.0.0-rc.1", 
    "@angular/compiler": "2.0.0-rc.1", 
    "@angular/core": "2.0.0-rc.1", 
    "@angular/http": "2.0.0-rc.1", 
    "@angular/platform-browser": "2.0.0-rc.1", 
    "@angular/platform-browser-dynamic": "2.0.0-rc.1", 
    "@angular/router": "3.0.0-alpha.7", 
    "@angular/router-deprecated": "2.0.0-rc.1", 
    "@angular/upgrade": "2.0.0-rc.1", 
    "angular2-in-memory-web-api": "0.0.11", 
    "bootstrap": "^3.3.6", 
    "core-js": "^2.4.0", 
    "reflect-metadata": "^0.1.3", 
    "rxjs": "5.0.0-beta.6", 
    "systemjs": "0.19.27", 
    "zone.js": "^0.6.12" 
    }, 
    "devDependencies": { 
    "concurrently": "^2.0.0", 
    "lite-server": "^2.2.0", 
    "typescript": "^1.8.10", 
    "typings": "^1.0.4" 
    } 
} 

我新的web開發,不知道還有什麼其他的文件/信息將是有益的,但將嘗試用什麼來更新帖子人們建議。我在OS X(El Capitan 10.11.5)上運行,使用Visual Studio Code開發,並使用Vivaldi(基於Chrome的)作爲我的Web瀏覽器。

回答

0

Angular將其所有模塊移動到bundles子目錄(see the breaking changes for rc.2 here)。在您的system.config中,您需要將路由器程序包映射到該目錄:

var packages = { 
    /* Other packages..*/ 
    '@angular/router': { main: 'bundles/router.umd', defaultExtension: 'js' } 
}