I follow the Tour of Heroes tutorial ; in the Routing section. I am using the 2.0.0-RC4 package.
I successfully reorganized the AppComponent into a wrapper for HeroesComponent . I also added routes, downloaded the necessary files, and performed the necessary download.
index.js - it was necessary to add a router for the browser platform, because this is what I read in the source of ng-router ; provideRouter returns false otherwise
<script src="node_modules/@angular/platform-browser/bundles/platform-browser.umd.js"></script> <script src="node_modules/@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js"></script> <script src="node_modules/@angular/router/bundles/router.umd.js"></script>
main.js
ng.platformBrowserDynamic.bootstrap(app.AppComponent, [ app.ROUTER_PROVIDERS ]);
app.routes.js
(function (app) { const routes = [ { path: 'heroes', component: app.HeroesComponent } ]; app.ROUTER_PROVIDERS = [ ng.router.provideRouter(routes) ]; })(window.app || (window.app = {}))
app.component.js
(function (app) { app.AppComponent = ng.core.Component({ selector: 'ig-app', directives: [ng.router.ROUTER_DIRECTIVES], providers: [app.HeroService], template:` <h1>{{title}}</h1> <a [routerLink]="['/heroes']">Heroes</a> <router-outlet></router-outlet> ` }).Class({ constructor: function() { this.title = 'Tour of Heroes'; } }); })(window.app || (window.app = {}));
This downloads my application using the Heroes link. But there is an error on the console.
EXCEPTION: Error: not available (in promise): error: routes cannot match: ''
And then I add /heroes to the url, the Heroes component does not load, and the following error appears on my console.
EXCEPTION: Error: uncleanness (in the promise): TypeError: cannot read the 'of' property from undefined
Any guidance on what I may be doing wrong?
EDIT
When I specify the route for '' in the routes file, for example ...
app.routes.js
(function (app) { const routes = [ { path: 'heroes', component: app.HeroesComponent }, { path: '', redirectTo: '/heroes', pathMatch: 'full' } ]; app.ROUTER_PROVIDERS = [ ng.router.provideRouter(routes) ]; })(window.app || (window.app = {}))
I get the second error mentioned above on both pages. If I try to install it on app.AppComponent , I get errors that suggest that I should have redirectTo