Stenciljs: route to new content and cannot change background

家住魔仙堡 提交于 2019-12-13 03:40:49

问题


I'm currently creating my first PWA with Stencil, PWA Toolkit and Ionic 4. I can not explain myself a behavior when switching from one page (ion-content) to another page. Here the situation:

CSS 1st page (app-home):

ion-content {
         --background: pink;
            }

CSS 2nd page (app-data):

ion-content {
         --background: white;
}

With the statement:

this.router.push ('/data', 'forward');

the app changes from page 1 to page 2. But the background remains pink and does not change as expected to white. When I refresh the url “/data” the background becomes white. When I then return to the first page the background remains white.

What am I doing wrong?


回答1:


It works this way because there are no css scoping in Stencil by default so rule for the for ion-content selector is applied twice in your page.

You need to prepend each style with a component selector to correctly scope them.

For example:

app-home ion-content {
  --background: pink;
}

Read more about styling in Stencil here



来源:https://stackoverflow.com/questions/55752193/stenciljs-route-to-new-content-and-cannot-change-background

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!