I use Context theming in my app, so that I can call a different layout dynamically, depending on a color passed as a get parameter in the url.
When I launch "npm start" to test my app it works perfectly, but when I use it with "npm run build", and visit the created page on my server, the app always loads the default theme, even when calling for a different color.
I am still a beginner in react, hope there is something I don't miss here. Any help would be great.
Code extract:
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
/*import './index-green.css'
import './index-blue.css'*/
import { ThemeProvider } from 'react-css-themr';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import { persistStore } from 'redux-persist'
import 'core-js/fn/array/find';
import 'core-js/fn/array/find-index';
import 'core-js/fn/array/map';
import configureStore from './store/configureStore';
const store = configureStore();
persistStore(store, {
blacklist: [
'event',
'polls',
'chat',
'userProfile',
'homeSubPage'
]
});
let params = new URLSearchParams(window.location.search);
let color = params.get('color');
let contextTheme;
switch (color) {
case "blue":
contextTheme = {
theme1: require('./assets/index-green.css'),
theme2: require('./assets/index-blue.css')
};
break;
default:
contextTheme = {
theme1: require('./assets/index-blue.css'),
theme2: require('./assets/index-green.css')
};
}
console.log("color is : "+ color); /* with npm start, blue has blue theme, but with npm run build, blue has green theme as well */
ReactDOM.render(
<ThemeProvider theme={contextTheme}>
<Provider store={store}>
<App />
</Provider>
</ThemeProvider>
, document.getElementById('root'));
registerServiceWorker();
Hi!
I use Context theming in my app, so that I can call a different layout dynamically, depending on a color passed as a get parameter in the url.
When I launch "npm start" to test my app it works perfectly, but when I use it with "npm run build", and visit the created page on my server, the app always loads the default theme, even when calling for a different color.
I am still a beginner in react, hope there is something I don't miss here. Any help would be great.
Code extract:
And the scripts part in the package.json: