Good Day.
JS newbie here. I am trying to make my "Home" button highlighted the moment I launch the web app from /, something like this. But instead i'm getting this.
I am using React router, my code:
Navigation.js . For bottom navigation bar
import React from 'react';
import { Nav, NavItem} from 'reactstrap';
import { NavLink } from 'react-router-dom';
..
const tabs = [{
route: "/home",
icon: faHome,
label: "Home"
},{
route: "/resources",
icon: faFolder,
label: "Files"
},{
route: "/vault",
icon: faDiceD20,
label: "the Vault"
},{
route: "/parts",
icon: faTools,
label: "Parts"
},{
route: "/login",
icon: faUserCircle,
label: "Me"
}]
const Navigation = (props) => {
<nav className="navbar fixed-bottom navbar-light d-block d-lg-none bottom-tab-nav" role="navigation">
<Nav className="w-100">
<div className=" d-flex flex-row justify-content-around w-100">
{
tabs.map((tab, index) =>(
<NavItem key={`tab-${index}`}>
<NavLink to={tab.route} className="nav-link bottom-nav-link" activeClassName="active">
<div className="row d-flex flex-column justify-content-center align-items-center">
<FontAwesomeIcon size="lg" icon={tab.icon}/>
<div className="bottom-tab-label">{tab.label}</div>
</div>
</NavLink>
</NavItem>
))
}
</div>
</Nav>
</nav>
};
App.js
I've added the line <NavLink to path="/" exact component={Home} activeClassName="active"/>
to try it out but it didn't make any difference.
import { BrowserRouter, Switch, Route, NavLink} from "react-router-dom";
import Navigation from './navigation';
<BrowserRouter>
<Navigation/>
<Switch>
<NavLink to path="/" exact component={Home} activeClassName="active"/>
<Route path="/home" exact component={Home}/>
<Route path="/vault" exact component={Vault} />
<Route path="/login" exact component={Login} />
<Route path="/parts" exact component={Parts} />
<Route path="/resources" exact component={Resources} />
</Switch>
</BrowserRouter>
My current workaround is to change the "start_url"
in manifest.json:
"start_url": "./home",
"display": "standalone",
"theme_color": "#FFFFFF",
"background_color": "#ffffff"
Thanks for reading. Please let me know if there are easier ways to achieve this. Thanks!