Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
45 changes: 45 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# React Router Basic Nav

Topics:

* Single Page Applications
* React Router V4 (react-router-dom)
* Routing, declarative component based routing
* Path and Component

## Project Description

* A starter pack project for all things React Router. Learn to set up a basic routing system within an application. Use this application to help guide your learning over the next couple of days.
* **Note** that this project has already been boilerplated for you. There is no need to run any installation steps beyond `yarn install`.

### Initialize Project

* cd into the repository and run `yarn install`
* run `yarn start`

### Steps for implementing React Router

* You'll notice we've already installed react-router-dom for you.
* `import` your BrowserRouter as Router inside your `index.js` file.
* Wrap your `<App />` component that you're passing to `ReactDOM.render()` with your new `Router` component.
* open up your chrome `REACT DEV TOOLS` and notice your app is now all wrapped in `BrowserRouter`
* inside the `REACT DEV TOOLS` expand `<BrowserRouter>` and highlight `<Router>` and notice that here is a `"history"` object on props and a `"match"` object on its state. These two objects are how all of our Router is going to work.

### Steps for "Declaring" your routes

* Inside of your `App.js` file `import { Route } from 'react-router-dom';`
* This is where we're going to declare and specify our router.
* 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.
* You should now be able to type `/`, `/about`, `/contact` after `localhost:PORT/` to see what's a

### Steps for setting up your Navigation

* Inside of `Navigation.js` `import { Link } from 'react-router-dom'`.
* Declare the `to` as the href on `<Link>` and specify the correct routes for your app to navigate towards.
* Head over to your app and start navigating. You should be able to see your URLS changing their paths as you go. Each path should display the proper component.

### Resources

* [Code Sandbox from Lecture](https://codesandbox.io/s/n58oqgwmP)
* [React Router 4 Quick Start Guide](https://reacttraining.com/react-router/web/guides/quick-start)
34 changes: 34 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "react-router-basic-nav2",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.3.1",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.9",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file not shown.
37 changes: 37 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
11 changes: 11 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.App {
text-align: center;
}

.Nav-Link {
padding: 2rem;
}

.nav-item {
margin-top: 1rem;
}
16 changes: 16 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { Route } from 'react-router-dom';

import './App.css';
import { Home, About, Contact, Navigation } from './components';

const App = () => (
<div>
<Navigation />
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/contact" component={Contact} />
</div>
);

export default App;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const About = () => <h1>About</h1>

export default About;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const Contact = () => <h1>Contact</h1>

export default Contact;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const Home = () => <h1>Home</h1>

export default Home;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { Link } from 'react-router-dom';

const Navigation = () => {
return (
<div>
<div className="App">
<h1>React Router Mini</h1>
<div>
<Link to="/">Home</Link>
</div>
<div>
<Link to="/about">About</Link>
</div>
<div>
<Link to="/contact">Contact</Link>
</div>
</div>
</div>
);
};

export default Navigation;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Home from './Home';
import About from './About';
import Contact from './Contact';
import Navigation from './Navigation';

export{ Home, About, Contact, Navigation };
5 changes: 5 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
body {
margin: 0;
padding: 0;
font-family: sans-serif;
}
15 changes: 15 additions & 0 deletions updated-basic-nav/react-router-basic-nav2/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';

import './index.css';
import App from './App';
import 'bootstrap/dist/css/bootstrap.css';


ReactDOM.render(
<Router>
<App />
</Router>,
document.getElementById('root')
);
Loading