2

I am trying to implement a dynamic route from my app.js. I have 2 pages. HomePage.js and ReportPageLayout.js.

When I try to navigate from HomePage to ReportPage, I am getting a status= cancelled. Image of Network tab

When i refresh the page in the browser, the data is fetched and rendered.Image status=200 and component rendered on dom

Here is my app.js file

import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Homepage from './pages/Homepage';
import ReportPage from './pages/ReportPageLayout';

export default function App() {
    return (
        <div className="App">
            <Router>
                <Switch>
                    <Route exact path="/" component={Homepage} />
                    <Route path="/:id" component={ReportPage} />
                </Switch>
            </Router>
        </div>
    );
}

    

Please help. Thank you in advance.

2 Answers2

1

for me, the following updation worked,

If you use are using React Router 5.3.x, check whether it is 5.3.3 in your package.json file.

If it is not 5.3.3 uninstall the last version then install the bug-free version which has been resolved by John and updated in version 5.3.3.

npm uninstall -S react-router-dom
npm install -S react-router-dom@5.3.3

0

As far as I know (not that much), in router-dom v5 you should nest the target component and not as an argument

import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Homepage from './pages/Homepage';
import ReportPage from './pages/ReportPageLayout';

export default function App() {
   return (
      <Fragment>
         <Switch>
            <Route exact path="/">
              <Homepage/>
            </Route>
            <Route path="/:id">
                <ReportPage/>
            </Route>
         </Switch>
      </Fragment>
   );
}

Furthermore, if you use suspense or importing data from, you should always create a fallback. I had the same thing here Delay in loading the array crushs the app

Blind2k
  • 350
  • 3
  • 13
  • No, RRDv5 has several [rendering methods]. There exists a `component` and `render` and `children` function props, as well as just implicitly rendering `children` components like your answer. – Drew Reese Apr 15 '22 at 06:01