Giter Club home page Giter Club logo

client-side-routing-mini's Introduction

React Router Mini

Topics:

  • Single Page Applications
  • Routing, declaritive component based routing
  • Browser vs Hash History
  • Path and Component

Project Description

Initialize Project

  • cd into repo and run npm install
  • run npm start

Steps for implementing React Router

  • You'll notice we've already installed react-router-dom for you.
  • Step 1: import { BrowserRouter as Router } from 'react-router-dom'; inside your index.js file.
  • Step 2: Wrap your <App /> component that you're passing to ReactDOM.render() with your <Router> </Router> component.
  • Step 3: open up your chrome REACT DEV TOOLS and notice your app is now all wrapped in BrowserRouter
  • Step 4: inside the REACT DEV TOOLS expand <BrowserRouter> and highlight <Router> and notice that here is a "history" object on props.

Steps for "Declaring" your routes

  • Step 5: inside of your App.js file import { Route } from 'react-router-dom';
    • this is where we're going to declare and specify our router.
  • Step 6: create 3 <Route /> setting their path prop equal to /, /about, /contact with their respective components.
    • be sure to incluce the exact prop on the root component for / to make sure that it's rendering the exact component and not all the other components.
  • Step 7: you should now be able to type /, /about, /contact after localhost:PORT/ to see what's a

Steps for setting up your Navigation

  • Step 8: inside of Navigation.js import { Link } from 'react-router-dom'
  • Step 9: delete NavLink and replace it with <Link />
    • Pro-tip: highlight NavLink and use cmd/ctrl + d to select them all at once.
  • Step 10: change the href on <Link> to to and specify the correct routes to navigate to.
  • Step 11: head over to your app and start navigating. You should be able to see your URLS changing their paths as you go.

Resources

client-side-routing-mini's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.