2

I'm trying to setup routing inside my application, but am getting following error in the console:

angular2-polyfills.js:138 Error: XHR error (404 Not Found) loading http://localhost:9000/angular2/router.js(...)

here is my boot.ts

// -- Typescript typings -------------------------------------------------------
/// <reference path="../typings/jquery.d.ts" />
/// <reference path="../typings/jqueryui.d.ts" />
//Imports ----------------------------------------------------------------------
import {Component, enableProdMode} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {
 ROUTER_DIRECTIVES,
 ROUTER_PROVIDERS,
 Router,
 RouteConfig,
} from 'angular2/router';
// -- Application Imports ------------------------------------------------------
import {NavbarComponent} from './components/navbar.component';
import {HomePage} from './pages/home.page';
// -- Enable production module -------------------------------------------------
enableProdMode();
// -- Component ----------------------------------------------------------------
@Component({
 selector: 'main-app',
 directives: [ ROUTER_DIRECTIVES, NavbarComponent ],
 template: `
 <app-navbar></app-navbar>
 <router-outlet></router-outlet>
 `
})
// -- Routing ------------------------------------------------------------------
@RouteConfig([
 { path: '/', name: 'root', redirectTo: ['/Home'] },
 { path: '/home', name: 'Home', component: HomePage }
])
// -- Class --------------------------------------------------------------------
export class MainApp {
 constructor(public router: Router) {}
}
// -- Bootstrap for application ------------------------------------------------
bootstrap(MainApp, [
 ROUTER_PROVIDERS
]);

and index.html -----

<!doctype html>
<html lang="en">
<head>
 <base href="/">
 <meta charset="UTF-8">
 <title>Angular2 starter</title>
 <!-- Application css -->
 <link href="dist/libraries/bundle.css" rel="stylesheet"></link>
 <link href="dist/styles/main.css" rel="stylesheet"></link>
</head>
<body>
 <main-app>Loading...</main-app>
 <!-- Application js -->
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
 <script src="dist/libraries/bundle.js"></script>
</body>
<!-- ES6-related imports -->
<script src="/node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="/node_modules/es6-shim/es6-shim.min.js"></script>
<script src="/node_modules/systemjs/dist/system.js"></script>
<script>
 //configure system loader
 System.config({defaultJSExtensions: true});
</script>
<script src="/node_modules/rxjs/bundles/Rx.js"></script>
<script src="/node_modules/angular2/bundles/angular2.min.js"></script>
<script>
 //bootstrap the Angular2 application
 System.import('dist/app/boot').catch(console.log.bind(console));
</script>
</html>
asked Jan 28, 2016 at 17:09

1 Answer 1

5

You are missing a script router.dev.js which is not shown very clearly in a lot of places and examples.

<script src="/node_modules/angular2/bundles/router.dev.js"></script>
answered Jan 28, 2016 at 17:14
Sign up to request clarification or add additional context in comments.

1 Comment

Solved the issue, there is also router.min.js available for slightly lower file size.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.