3
I’m creating an app in Nodejs, React & Redux here at the company. And I have a page that is Content, in it I have two navigation bars and a common area for content. In this common area I’m using Switch to control the routes, but I want a route (component) to enter as soon as the app is loaded, IE, be the default, but I’m not finding documentation about it, can help me, below follows the code.
import React, { Fragment } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Navbar from './Navbar';
import Topnavbar from './Topnavbar';
import Dashboard from './Dashboard';
import Profile from './Profile';
const Content = () => {
return (
<Router>
<Fragment>
<div id='wrapper'>
<Navbar />
<div id='content-wrapper' className='d-flex flex-column'>
<div id='content'>
<Topnavbar />
<Switch>
<Route exact path='/dashboard' component={Dashboard} />
<Route exact path='/profile' component={Profile} />
</Switch>
</div>
</div>
</div>
</Fragment>
</Router>
);
};
export default Content;
I want the Dashboard component to be the default. How to determine that a route is the default on the switch?
Thank you.
Thanks Andrew, I used Redirect but instead of a "/" I used "/content" to "/Dashboard" because my application uses the "/" to always go to login, since it runs on an intranet and has the need to always login to access it.
– user152677
I’m glad it worked out.
– Andrew Ribeiro