0

I want to use React Component to get id matches but it gives error when going to url : http://localhost:8080/portfolio/1 and run fine for other url. Error :

GET http://localhost:8080/portfolio/bundle.js 404 (Not Found)      1:1  
Refused to execute script from 'http://localhost:8080/portfolio/bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

AppRouter.js

  import React from 'react';
  import { BrowserRouter, Route, Switch, Link,NavLink } from 'react-router-dom';
  import Home from '../Components/Home';
  import Contact from '../Components/Contact';
  import PortfolioItemPage from '../Components/PortfolioItemPage.js'; 
  import NotFound from '../Components/NotFound.js';
  import Header from '../Components/Header';


  const AppRouter = () => (
 <BrowserRouter>
   <div>

     <Header/>
     <Switch>
         <Route path="/" component={Home} exact={true} />
         <Route path="/portfolio/:id" component={PortfolioItemPage} />

         <Route path="/contact" component={Contact}/>
         <Route component={NotFound} />
     </Switch>
   </div>
 </BrowserRouter>
);

  export default AppRouter;

Home Page

PortfolioItemPage.js

  import React from 'react';
  const PortfolioItemPage = (props) => {
  console.log(props);
    return (
   <div>
     <h1>Hii there...</h1>
    </div>
   );
   };
     export default PortfolioItemPage;

What to do so that i cannot get error when i go to http://localhost:8080/portfolio/1 ?

Shiv Kumar
  • 31
  • 3

1 Answers1

0

Looks like your App tries to load bundle.js from relative path http://localhost:8080/portfolio/.

Try to add <base href="/" /> into <html><head> to force your App load assets from the root URL.

pyotruk
  • 81
  • 1
  • 3