Use absolute paths for templates again


#1

Hello,

I am using a custom Page decorator that extends the functionality of the standard Component.
This worked well until the introduction of relative paths for templateUrl:

If I do this in src/my_page.ts:

import {Page} from './path/to/page';

@Page({
  templateUrl: 'foo.html'
})
class Foo{}

the template is not searched in the src folder, but in the www folder (if I create www/foo.html it works). I found a workaround for this (creating a symbolic link inside www to src), but this causes trouble elsewhere. Is there a way to make relative urls possible when using a custom Page decorator? Alternatively: How can I activate absolute paths again, such that I can specify the templateUrl relative to the root of the src/ directory?

I already tried a lot of things like setting moduleId manually (doesn’t work, neither with webpack nor with rollup) but I can’t find a solution :frowning:

Thank you in advance!

Edit: My custom Page decorator looks like this:

export function Page(options: any = {}) {
  if (!options.changeDetection) {
    options.changeDetection = ChangeDetectionStrategy.OnPush;
  }
  return function(target) {
    target.prototype.ionViewWillEnter = function() {
      if (_redirect) {
        this.nav.push(_redirect[0], _redirect[1]);
        _redirect = undefined;
      }
    }
    Component(options)(target);
  }
}

Help us test Webpack support in Ionic 2 App Scripts!
#2

Just some ideas:

  • You are using RC.0 or RC.1 right?
  • The class shouldn’t be exported ? export class Foo { …
  • Did you define your page in app.module.ts in declarations and entryComponents?

PS.: Try these ideas without custom page decorator and without copying stuffs in www (compilation is a must have from RC.0)


#3

thank you for your answer!

  • Yes, I’m using the latest version
  • neither the missing export nor missing declarations are the problem: If I don’t use the custom decorator, everything works fine and relative URLs work. But once I use the custom decorator, the templates are searched inside the www/ folder, and I don’t find a way to change that :frowning:

#4

I fixed the problem now by not using a custom page decorator anymore. I tried a lot of things but relative urls apparently rely on some black magic I don’t understand…