React App Shows White Screen After Adding New Routes

  Kiến thức lập trình

I’m working on a React application and recently added new routes to my App.jsx file. However, after adding these routes, my application only shows a white screen. When I remove the new code, the landing page displays correctly again.

Here is the relevant excerpt from my App.jsx file:

import Landing from './landing';
import Login from './login';
import {
  BrowserRouter as Router,
  Route,
  Switch
} from 'react-router-dom';

const Main = () => {
  return (
    <Router>
      <Switch>
        <Route path="/landing" exact component={Landing} />
        <Route path="/login" component={Login} />
      </Switch>
    </Router>
  );
};

export default Main;

I’ve checked the following:

There are no errors in the browser console.
The Landing and Login components are correctly exported.
The paths in the routes match the paths I’m trying to navigate to.
react-router-dom is properly installed.
I’ve restarted the development server.
There are no typos or case sensitivity issues in the import statements.
Despite these checks, the white screen persists. What could be causing this issue, and how can I resolve it?

What I Expected:

I expected the application to navigate to the Landing component when accessing /landing and to the Login component when accessing /login.

What Actually Happened:

After adding the new routes, the application only shows a white screen. When I remove the new code, the landing page displays correctly again.

New contributor

Soumya Bokare is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT