mercredi 2 janvier 2019

How can I load a stylesheet dynamically in an Ember route?

I'd like to breakup my stylesheet and import smaller chunks on route load. With the code below I'm able to successfully create the <link> element with the correct attributes. Once the DOM is loaded is appears in the <head> just as I would have expected it as if I loaded in index.html. However, the styles don't load.

beforeModel() {
  let link = document.createElement('link');
  const rootURL = this.get('router.rootURL');

  link.rel = "stylesheet";
  link.type = "css";
  link.href = `${rootURL}assets/muh_sheet.css">`;

  document.head.appendChild(link);
}

It shows up in the <head> tag with the correct src, no console errors. Still doesn't load the styles.




Aucun commentaire:

Enregistrer un commentaire