Skip to content Skip to sidebar Skip to footer

How To Change Styles While Route Changing In React?

When route(react-route) changing, how can I load or remove the styles relevant to the new page? I really don't know who is in charge of this function , react or webpack or react-ro

Solution 1:

change it like this

Page1:

import style from'./page1style.css';
 exportdefaultclassPage1extendsReact.Component {
   render () {
     return<divclassName={style.someClass} />
   }
 }

what your code does is to load as general css and that's why it load all of it. This way would be more modular and easy to handle

Post a Comment for "How To Change Styles While Route Changing In React?"