2

I have a react app setup with CRA.

In my App.js I would load my css files, components and define my routes.

import 'semantic-ui-css/semantic.min.css';
import './css/global.css';
import './index.css';
import 'react-grid-layout/css/styles.css';
import 'react-resizable/css/styles.css';
import ResetPassword from './pages/ResetPassword';
import ResetPasswordConfirm from './pages/ResetPasswordConfirm';

.... 


return (
          <Router>
                <Switch>
                    <Route path="/reset-password">
                        <ResetPassword intl={intl} />
                    </Route>
                    <Route path="/about-us">
                        ...
                    </Route>
             ....
); 

Now, I want to implement route-based code splitting with React.lazy.

I changed my component imports as follows:

const ResetPassword = lazy(() => import('./pages/ResetPassword'));
const ResetPasswordConfirm = lazy(() => import('./pages/ResetPasswordConfirm'));

and I updated my return method as follows:

return (
      <Router>
                <Suspense fallback={<div>Loading...</div>}>
                    <Switch>
                         <Route path="/reset-password">
                            <ResetPassword intl={intl} />
                        </Route>
                        <Route path="/about-us">
                            ...
                        </Route>

);

The problem I'm facing is that none of my CSS files which I import above in my App.js are being loaded into the components.

I didn't eject my app from CRA so I don't have any custom webpack config.

Alk
  • 5,215
  • 8
  • 47
  • 116
  • I'm experiencing the same issue. Did you find a solution that you could share?? – kuhnflyfish Oct 24 '22 at 20:02
  • 3
    @kuhnflyfish if I remember correctly, the CSS files were being imported, however they weren't imported in the same order as before and as a result the CSS hierarchy changed and different styles were being applied - I ended up explicitly importing the CSS in the components that needed them instead of doing so in App.js - not the best solution but it resolved my issue. – Alk Oct 24 '22 at 22:30
  • how to fix this but not like above @Alk – Adarsh Raj Nov 02 '22 at 04:26

0 Answers0