User Story
As a user, I can navigate via navbar links or buttons to the following pages when I am not logged in the app and see the URL change accordingly whenever I am on a different page: Home, Games -- and when I am logged in, I can navigate to the following pages and see the URL change accordingly: Practices, Profile, Submissions.
AC
NAVBAR AC:
WHEN I go to the login page,
THEN I will be on the Home page,
AND the navbar should display links to Home, Games, and Log In,
AND when I log in,
THEN the navbar should display links to Home, Games, Practices, Submissions, Profile, and Log Out.
Routing AC:
WHEN I log in, I should be on the Home page, and the url should display '/home',
THEN when I click on the Games navbar item, I should go to the Games page, and the url should display '/games',
THEN when I click on the Practics navbar item, I should go to the Practices page, and the url should display '/practices',
THEN when I click on the Submissions navbar item, I should go to the Submissions page, and the url should display '/submissions',
THEN when I click on the Profile navbar item, I should go to the Profile page, and the url should display '/profile'.
Dev Notes
- In
components
> pages
: Create all the components we need for the pages in this app > pages folder: Home; Games; SingleGame, Practices, Submissions, Profile - with corresponding js and scss files and create classes and components in each file respectively.
App.js
> import all the files you just created here.
- Install
React Router DOM
. (npm install react-router-dom
)
App.js
> after the firebase imports, import 4 different components from the React Router DOM library: BrowserRoute
, Route
, Redirect
, Switch
.
App.js
: Add the objects for Route
and PrivateRoute
at the top after the fbConnection
and before the class
component.
App.js
> inside the html div in the return > Add the BrowseRouter
> Inside the BrowserRouter
tag > add React.Fragment
tag > Inside React.Fragment
> add the MyNavbar
tag - and it should include the authed
attribute > then add a div with a class of container and another div with a class of row > then define the content for the route here — use the Switch
component: -1-Add a private route for all the pages inside the app (Practices, Submissions, Profile); -2-Add a route for the Auth
/Home page and for the Games and SingleGame pages ; -3-add a Redirect
component for any incorrect url the user types in on this site.
- In
MyNavbar.js
file: Update the navbar to use the correct paths for its menus:
- Install reactstrap - if not yet installed;
- Copy Navbar code from reactstrap into the div in the return in the
MyNavbar.js
component;
- Import the reactstrap navbar components at the top of the
MyNavbar.js
file (after the React package import);
- import
NavLink
- as an RRNavLink
from the react-router-dom package here, too;
- update code for
isOpen
and toggle
hooks from reactstrap navbar code;
- IN APP.JS: I should already be passing in
authed
to the MyNavbar
component.
- BACK in
MyNavbar.js
: Add static propTypes for the authed
props.
- Control what user sees in navbar before logging in and after: Inside the
render
, before the return
, write a buildNavbar
function that uses the authed
variable and when it is true, it builds the navbar and uses the NavLink
component with a tag of RRNavLink
for each navbar item, and include the appropriate paths for each in a to
attribute here; when authed
is false, the navbar includes the Home, Games and Log In Links. So > copy the loginClickEvent function from the Auth.js
file here and delete the firebase imports in Auth.js
; add the NavItem for the Log In button and the onClick
event handler in the link tag with the loginClickEvent
function I just added above.
- Delete the default
href
attributes in the Links.
- call this
buildNavbar
function inside the navbar reactstrap code - inside the Collapse
tag there.
- Add a CSS class that makes the hand pointer when user hovers over the nav item for the Log Out link (pointer is not displayed by default).(create the class in the
MyNavbar.scss
file and then add it here for the Log Out and Log In link tags).
- In
Games.js
: import the name Link component from the react-router-dom package and add a Link tag on the Games page to navigate to the Single Game page. Define add the to
attributes with the url where they should take the user.