Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Router: Refused to execute script or styles

When I browse http://localhost:8080/create , its working fine but when browse http://localhost:8080/create/344 or http://localhost:8080/edit/224 I'm getting this error:

Refused to apply style from 'http://localhost:8080/edit/dist/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

2345:12 GET http://localhost:8080/edit/dist/bundle.js 404 (Not Found) 345:1

Refused to execute script from 'http://localhost:8080/editt/dist/bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Here is my code:

<BrowserRouter>
    <Switch>
        <Route exact={true} path="/" component={Dashboard} />
        <Route path="/edit/:id" component={EditPost}/>
        <Route path="/create" component={AddPost} />
        <Route component={NotFoundPage}/>
    </Switch>
</BrowserRouter>

check this screenshot please:

enter image description here

here is my webpack config file: https://pastebin.com/d5vx8niQ project file: https://drive.google.com/file/d/1IYcuJTbklXYi53XvIcNRJtb-tLOO4g1j/view?usp=sharing

like image 769
Mina Avatar asked Jun 17 '26 17:06

Mina


2 Answers

Add <base href="/"> in index.html head before linking all css files. (Source: https://github.com/froala/angular-froala/issues/170)

like image 60
Arkady Elterman Avatar answered Jun 19 '26 06:06

Arkady Elterman


Just use /dist/main.css & /dist/bundle.js instead of dist/main.css & dist/bundle.js in your HTML.

like image 22
Delowar Hosain Avatar answered Jun 19 '26 07:06

Delowar Hosain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!