prasunnandy's avatar

React Route is not working in Laravel React Scaffold project

I am using React routes like this in my Laravel React project.

It was working fine in localhost. After uploading the project to the live server route doesn't work. when I remove "exact" keyword from the route it shows the page but does not change the page because it's obvious without exact keyword it does not change. but the main problem comes when I use "exact" keyword on the router like the above example, its shows nothing on the server. the page went blank. I think it's the problem for "exact" keyword. So can anyone please tell me what is the problem and how to solve it?

0 likes
2 replies
jagged_little_phil's avatar

Are you wrapping your routes in a "switch" component?

Like this:

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import PageOne from './PageOne';
import PageTwo from './PageTwo';

ReactDOM.render(
  <React.StrictMode>
    <BrowserRouter>
      <Switch>
        <Route exact path="/" component={PageOne} />
        <Route exact path="/page2" component={PageTwo} />
      </Switch>
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById('root')
);
prasunnandy's avatar

Hi! Solved it. I didn't create a subdomain for my app. That's why routes weren't working properly. Thanks for help!!

Please or to participate in this conversation.