1

I have two modern UI pages Test1 and Test2. In Test1 page, I am using SPFx webpart to hide control on particular pages. I am using CSS:

global {
    div[class^='pageTitle_'] {
        display:none;
    }
}

when I navigate to another page Test2 where I have not used any SPFx control and its a simple modern page it inherit same CSS and page title gets hide until I refresh it manually.

  • Can you add more details and code to the question ? – Ravi Nov 12 '19 at 5:43
  • added some detail – kumar Nov 12 '19 at 5:52
  • just to confirm that it's a webpart and not an extension, right ? – Ravi Nov 12 '19 at 6:50
  • webpart but i am omly using in one page – kumar Nov 12 '19 at 6:55
  • then this should not happen. can you try removing global from css and check ? – Ravi Nov 12 '19 at 6:56
1

Create a file , let's say customCSS.css inside your component folder and paste the below code :

div[class^='pageTitle_']{
  display: none ;
}

Now in your main .ts file call this css file with the following syntax on top of the code :

require("../../webparts/WebpartName/components/customCSS.css");

To refresh the page on load only once, paste the below code in componentDidMount :

window.onload = function() {
    if(!window.location.hash) {
        window.location = window.location + '#loaded';
        window.location.reload();
    }
}
  • i tried this , but it still affect this css in another pages as well – kumar Nov 13 '19 at 3:05
  • This is so strange behaviour as I am using same code in all of my web parts and it hides the page title only for the page on which the web part has been inserted. – Ravi Nov 13 '19 at 3:44
  • i added this css it hide the page title but it also hide page title from another page where this webpart is not present it happen only if i navigate through pages from navigation ,if manualyy refresh the pages it donot happen – kumar Nov 13 '19 at 4:25
  • can i refresh page once when i navigate to page for workaround – kumar Nov 13 '19 at 5:46
  • yes that seems to be workaround for now. Also it's not happening for me even if I navigate to other page from navigation. – Ravi Nov 13 '19 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.