简体   繁体   中英

styles.css is not being applied to only one page in react and node.js app

So i have a website built in react and uses node.js, all pages load correctly but one, it does not load the css correctly, i am not sure why. Another interesting thing is that it is not present in the developer tools either, Firefox and Google.

The below in in my.html file

<link rel="stylesheet" type="text/css" href="styles.css" />

when i load my project on localhost, i get this error.

The stylesheet http://localhost:3001/product/styles.css was not loaded because its MIME type, "text/html", is not "text/css".

If anyone can help that would be great as I can't seem to figure out why. Note: i removed comments from the beginning of my css file.

It is necessary to include styles in ReactJS through import statement:

import './css/component.css';

See a complete example here

And also there is a React docs "Adding a Stylesheet"

It's not necessary as pointed out by StepUp. Therefore, you should probably use them with JavaScript import statement.

Where is your css located? The file name is correct?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM