Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 Quick Start - 'Cannot Get' Message

I've been trying to do the quick start guide for Angular2. I did the example as instructed in the quick guide. However, when I ran it, it displayed the following message 'Cannot Get'. Does anyone know why this is happening?

boot.js file

// JavaScript source code (function (app) {     document.addEventListener('DOMContentLoaded', function () {         ng.platform.browser.bootstrap(app.AppComponent);     }); })(window.app || (window.app = {})); 

The app.component.js file

(function (app) {     app.AppComponent = ng.core.Component({         Selector: 'my-app',         template: '<h1>My First Angular 2 App </h1>'     })     .class({         constructor: function () { }     }); })(window.app || window.app == {}); 

The index file

<html>  <head>     <title>Angular 2 QuickStart</title>      <!-- 1. Load libraries -->     <script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script>     <script src="https://code.angularjs.org/2.0.0-beta.0/Rx.umd.js"></script>     <script src="https://code.angularjs.org/2.0.0-beta.0/angular2-all.umd.dev.js"></script>      <!-- 2. Load our 'modules' -->     <script src='app/app.component.js'></script>     <script src='app/boot.js'></script>  </head>  <!-- 3. Display the application --> <body>     <my-app>Loading...</my-app> </body>  </html> 

Finally, the package.json file

{   "name": "angular2-quickstart",   "version": "1.0.0",   "scripts": {     "start": "npm run lite",     "lite": "lite-server"   },   "license": "ISC",   "dependencies": {     "angular2": "2.0.0-beta.0",     "systemjs": "0.19.6",     "es6-promise": "^3.0.2",     "es6-shim": "^0.33.3",     "reflect-metadata": "0.1.2",     "rxjs": "5.0.0-beta.0",     "zone.js": "0.5.10"   },   "devDependencies": {     "lite-server": "^1.3.1"   } } 

I ran the line 'npm start' which opened the browser and displayed 'Cannot Get'

like image 367
Josiane Ferice Avatar asked Jan 14 '16 21:01

Josiane Ferice


2 Answers

I got this error when index.html was not in the correct folder.

If that is the case, putting it in the main angular project's root folder should resolve the error.

like image 94
Melaz Avatar answered Sep 19 '22 14:09

Melaz


Background

I have had the same problem: Cannot GET / pagename on every page. I searched the internet but did not found a solution like this one.

My project resided inside a folder with ASCII spaces since the repository name also contained spaces.

Answer

The folder in which your project resides, should not contain any space or ASCII Character "%20".

enter image description here

After this change my project did not give the Cannot GET / pagename error.

like image 39
Brampage Avatar answered Sep 20 '22 14:09

Brampage