0

After upgrading to RC4 I have this issue configuring router:

ng.router.RouteConfig is not a function

I am using plain JavaScript.

This is how I bootstrap:

ng.platform.browser.bootstrap(AppComponent,[
        ng.router.ROUTER_PROVIDERS,
        new ng.core.provide(ng.core.PLATFORM_DIRECTIVES, {useValue: [ng.router.ROUTER_DIRECTIVES], multi: true}),
        new ng.core.provide(ng.common.LocationStrategy, {useClass: ng.common.HashLocationStrategy})
]);

And my Main Component looks like this (removed unnecessary code):

var AppComponent = ng.core
    .Component({
        selector: 'app',
        templateUrl: 'app/app.view.html',
        directives: [
            ng.router.ROUTER_DIRECTIVES
        ]
    })
    .Class({
        constructor: function() {}
    });

AppComponent = ng.router
    .RouteConfig([
        {path: '/search', name:"Search", component: SearchComponent},
        {path: '/results', name:"Results", component: ResultsComponent },
        {path: "*", component: SearchComponent }
    ])
    (AppComponent);

I am using: angular: 2.0.0-rc.4 router: 3.0.0-beta.1

This is my scrip includes:

    <script src="libs/angular/2.0.0-rc.4/shim.min.js"></script>
    <script src="libs/angular/2.0.0-rc.4/zone.js"></script>
    <script src="libs/angular/2.0.0-rc.4/Reflect.js"></script>
    <script src="libs/angular/2.0.0-rc.4/Rx.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/core.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/common.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/compiler.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/platform-browser.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/platform-browser-dynamic.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/http.umd.js"></script>
    <script src="libs/angular/2.0.0-rc.4/router.umd.js"></script>
Daniel Dudas
  • 2,972
  • 3
  • 27
  • 39
  • Hey, did you figure it out? I have the same problem and I have been trying stuff for hours now... – Maxime Laval Jul 20 '16 at 16:39
  • @MaximeLaval No. I still have this error and I didn't find a way to fix it. If you find a solution please post as answer because I still want to resolve it. – Daniel Dudas Jul 20 '16 at 20:08

1 Answers1

1

I guess it is RouterConfig instead of RouteConfig .

Code Sample from Angular tutorial Link

import { provideRouter, RouterConfig }  from '@angular/router';
import { HeroesComponent } from './heroes.component';

const routes: RouterConfig = [
  {
    path: 'heroes',
    component: HeroesComponent
  }
];

Update

.Class({
    constructor: [ ng.router.Router, function(router) {
            router.config([
                { path: '/dashboard', name: 'Dashboard', component: DashboardComponent, useAsDefault: true },
                { path: '/heroes-list', name: 'Heroes', component: HeroesComponent },                
                { path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent }
            ]);

    }]
});
Kalpesh Dusane
  • 1,477
  • 3
  • 20
  • 27
Atal Kishore
  • 4,480
  • 3
  • 18
  • 27
  • 1
    If I try with `RouterConfig` I am getting almost same error: `ng.router.RouterConfig is not a function` On official cheat sheet it's `ng.router.RouteConfig`. Here: https://angular.io/docs/js/latest/guide/cheatsheet.html – Daniel Dudas Jul 15 '16 at 13:40
  • 1
    I have no idea about angular 2 with javascript check this answer it might help you http://stackoverflow.com/questions/33711236/angular-2-routing-in-plain-javascript-no-typescript – Atal Kishore Jul 15 '16 at 13:52
  • The question/answers on that question are old and are using version 1 of router, the one used in beta versions. – Daniel Dudas Jul 15 '16 at 14:01