Issue with Next.js app styles persisting on pages after page refresh

I am currently working on my first next.js project, transitioning from create-react-app, and I've encountered an unusual issue. When I refresh the home page, the CSS styles persist without any problem. However, if I navigate to a different page like "/profile" and then refresh, all the CSS styles disappear completely.

Here is how my folders are structured:

https://i.stack.imgur.com/u9nd6.png

page.js: https://i.stack.imgur.com/wbtVH.png

    
import BlogSection from '../components/BlogSection.jsx'
import Main from '../components/Main.jsx'
import ServiceSection from '../components/ServiceSection.jsx'
import '../styles/App.css'

export default function Home() {
    return (
        <div className='home-page-container'>
            <Main />
            <ServiceSection 
                homePage
            />
            <BlogSection />
        </div>
    )
}

layout.js: https://i.stack.imgur.com/ld7cQ.png

import Footer from '@/components/Footer.jsx';
import Header from '../components/Header.jsx';

export const metadata = {
  title: "Movan",
  description: "Generated by create next app",
};

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Header />
        {children}
        <Footer />
      </body>
    </html>
  );
}

I'm feeling a bit lost as I'm not very familiar with Next.js. Any guidance or advice on what I could try would be greatly appreciated.

Answer №1

If you're encountering issues, it may be due to the absence of the globals.css file in your public layout.js file.

To resolve this problem, simply insert the following line at the beginning of your code:

import "./globals.css"

Alternatively, if your CSS file is located at ../styles/App.css, you can add:

import "../styles/App.css"

Your modified layout.js would look like this:

import "../styles/App.css" // ./globals.css

import Footer from '@/components/Footer.jsx';
import Header from '../components/Header.jsx';

export const metadata = {
  title: "Movan",
  description: "Generated by create next app"",
};

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <Header />
        {children}
        <Footer />
      </body>
    </html>
  );
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for preventing tiny separation lines from appearing above and below unordered list elements

I am attempting to utilize twitter bootstrap to create a select-option style list. How can I eliminate the thin separation lines above and below the list of items? Refer to the screenshot: Below is the visible code snippet. It would be best to view the j ...

Can a straightforward filtering option be incorporated into the column headers while utilizing the Mui datagrid?

Currently, I am incorporating the Mui data-grid into my React application. My project manager has requested that he wants to filter the data in a specific way like showin in this image. I am unsure if this is achievable and how to go about implementing it ...

The TypeScript in the React-Native app is lacking certain properties compared to the expected type

I recently integrated the https://github.com/react-native-community/react-native-modal library into my project and now I need to create a wrapper Modal class. Initially, I set up an Interface that extends multiple interfaces from both react-native and reac ...

What is the best method for incorporating this into our website: React js, or any other website editor available?

What is the best way to incorporate this into our website - React JS or another platform? Editor ...

Why is it important to implement an Authorization flow when developing a Stripe App for its marketplace?

As I develop a Stripe App for its marketplace, two distinct methods of server calls are at play. One involves Server-Side Logic, outlined in this diagram: https://i.stack.imgur.com/cKlOS.png The other encompasses Authorization flows, depicted in this di ...

The act of exporting components from the main index file allows for

I have assigned a components folder where I created various components that I want to export to the index.js file and then export all of them from there. This is an example from one of the components files: export default ToggleSwitch; Now, in the inde ...

Encountered webpack errors during the build process on CentOS 7 resulting in a failed nextjs

I'm facing an issue while trying to deploy a next.js application on a CentOS server. When I attempt to build it using npm run build, the following error is generated: Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --updat ...

Dealing with React Native text overflowing beyond the screen width when using FlexWrap

I'm currently working on implementing a component in react native that consists of a row containing and components, but I'm struggling to achieve the desired outcome. Here's my current code: <View style={{ flexDirection: ...

Examining the visual rendering of a webpage using next.js and jest

Is there a way to verify the accuracy of page rendering in next.js using images instead of HTML comparison? Currently, I have only come across a method to theoretically "render" the component into an HTML tags tree using toJSON(): import React from ' ...

The environment variables remain static within the .next directory of Next.js production

After building a full-stack app using Netxjs, I generated a build and uploaded the .next folder on Cpanel. Setting up my node app: Here is a screenshot of my node app console: https://i.stack.imgur.com/sbpIP.jpg I added environment variables in both node ...

I am unable to view the most recent version of json-parse-better-errors on NPM

I've encountered an issue while trying to execute the npx create-react-app command on my local machine. The script fails during the installation process of json-parse-better-errors. It seems like it is looking for version 1.0.2, which is stated as the ...

Is there a way to adjust the font-weight of the headers in a React Material UI table?

Struggling to override the style of "MuiTableCell-head" even after multiple attempts. `attempted to use makeStyles for overwriting .MuiTableCell-head` const useStyles = makeStyles({ test: { "& .MuiTableCell-head": { fontweight: ...

Ways to resolve the error "Uncaught TypeError: data.map is not a function"

Currently developing an app using reactJS and encountering the following error in the console when using the map function: TypeError: data.map is not a function. Despite successful API data calling as confirmed by console.log, the error persists when tryin ...

Utilize functional JS code within a TypeScript environment

Attempting to integrate this code into a TypeScript project, it is a modified version of the react-custom-scrollbars. I am struggling with TypeScript in regards to declaring types for style and props. In this particular case, I prefer to bypass type check ...

Struggling to properly align a div on top of an image

view image description herei need assistance with centering the div over the background image. I attempted to use relative positioning for the container and absolute positioning for the elements, but it did not yield the desired result. The code snippet be ...

How I am able to access this.state in React without the need for binding or arrow functions

Understanding the concept of arrow functions inheriting the parent context is crucial in React development. Consider this React component example: import React, { Component } from 'react'; import { View, Text } from 'react-native'; i ...

Issue with React Material-UI Select component not displaying the chosen value

Hi there, I'm facing a problem with the MUI select function while trying to choose a country. I can see that when I select a country, its value changes, but nothing appears inside the select box. const [selectedCountry, setSelectedCountry] = useState( ...

Stop the ability to navigate backwards using the useNavigate hook

Is it possible to disable back navigation in React by utilizing the useNavigate hook? I have been using navigate("/",{replace: true}) temporarily, but am searching for a more elegant solution. ...

Guide to storing publicUrl from product form in NextJS using Supabase

Seeking assistance as a newcomer to Supabase, I find myself struggling with certain concepts. My goal is to design a basic form where I can upload an image, input name, description, and price. Afterwards, the image should be saved in a bucket while the in ...

"Error: Unable to access the desired webpage through the dropdown menu link

My dropdown menu is experiencing an issue with the Profile link. When clicked, it does not redirect to the /user page as intended. Instead, nothing happens except the menu closing. The component responsible for this behavior is: Navbar.js const Navbar = ...