-2

I was playing with Angular2 beta tutorials, and discovered how magnificient are ES6 new way of importing modules & systemjs.

However, there's a thing I can't make it to work.

Everything works fine, UNTIL you have second level page, system.js is configured only for 1st level page

here is plnkr with the issue http://plnkr.co/edit/afsJY6tzrSeYMOtzUnXQ?p=preview

once run, as you can see, homepage works but the second level page is not working.

Must be something with systemjs configuration, I have my explanations and I fully understand why it does not work, and I have found a workaround, but I don't like it, can you please point me to the correct way?

this part:

System.import('app/boot').then(null, console.error.bind(console));

could be easily fixed by using

System.import('/app/boot.js').then(null, console.error.bind(console));

but then there in the boot.ts

import {bootstrap}    from 'angular2/platform/browser'
import {AppComponent} from './app.component'

bootstrap(AppComponent);

I don't know how to fix the './app.component' because if I do '../app/app.component.js' then the typescript compiler blames, so, how's the correct strategy?

Luca Trazzi
  • 1,240
  • 1
  • 13
  • 30

1 Answers1

0

I'm not sure what the recommended way would be, as I'm still a beginner as well, but one way is to add maps to the config:

System.config({
  packages: {        
    app: {
      format: 'register',
      defaultExtension: 'js'
    }
  },
  map: {
    app: '../app' // <--
  }
});

You could of course replace the relative ../app with something absolute like /app when you are running it locally.

Henrik Karlsson
  • 5,559
  • 4
  • 25
  • 42
  • interesting, could be a way, I have to add all possible relative paths for add? means ../app ../../app ../../../app and so on to a maximum of N levels? – Luca Trazzi Jan 07 '16 at 23:38
  • Probably you could add an absolute path, like /app, right? – Henrik Karlsson Jan 08 '16 at 08:27
  • I can do for the boot without any problem, problem arise when I use the Es6 import, there I can't use absolute path, like import {AppComponent} from './app.component – Luca Trazzi Jan 08 '16 at 17:46