Angular 2 Routing in plain Javascript (No Typescript)

后端 未结 3 1574
北海茫月
北海茫月 2021-01-13 10:31

So I have been battling to get the router working in Angular2 without using Typescript. I can\'t seem to find any examples, other than some typescript compiled javascript th

3条回答
  •  清歌不尽
    2021-01-13 11:24

    You can use router.config() method to specify list of routes. Here is an example written purely in ES5 (see this plunk):

    var App = Component({
      selector: 'my-app',
      directives: [RouterOutlet, RouterLink],
      template: (
        '

    Hello, World!!!

    ' + '' + '' ) }) .Class({ constructor: function(router) { router.config([ { path: '/index': component: Index, name: 'Index' }, { path: '/home': component: Home, name: 'Home' } ]) } }); App.parameters = [Router];

    PS Decorators are part of ES2016 (formerly ES7). They're javascript and supported by Babel. I think you should not be afraid to use them.

提交回复
热议问题