1

Very new to react, I'm trying to separate the landingpage, login/signup and the app in react router but I cant to make it work, the page always loads the layout of the landing page and under it the login.

// Imports
import 'bootstrap/scss/bootstrap.scss';
import React from 'react';
import ReactDOM from 'react-dom';
import {
    BrowserRouter as Router, Route
} from 'react-router-dom';
import * as serviceWorker from './serviceWorker';

// Data
import Landing from "./components/landing/landing";
import login from './components/app/auth/login';

// App
const Root = () => (
    <Router>
        <Route path="/" component={Landing} />
        <Route path="/login" component={login} />
    </Router>
)

ReactDOM.render(
    <Root />,
    document.querySelector("#root")
)

// Service worker
serviceWorker.unregister();

1 Answer 1

3

You have to use exact path within the component. It will look like <Route exact path="/" component={Landing} />

The same goes for the login page.

Sign up to request clarification or add additional context in comments.

1 Comment

No worries. Use just path when routing components like navbars and footers so they load on various pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.