Code Monkey home page Code Monkey logo

react-router-simple-dentist-site's Introduction

React Router Simple Dentist Website

This website is a simple example of how to route URLs to different components using react-router-dom.

See the site live here: https://react-router-dentist.herokuapp.com/

Author Note

This repo uses react-router-dom specifically instead of react-router. Consider this discussion thread describing the difference between the two:

remix-run/react-router#4648

Summary

Here's how you can hook up a nav bar to each component, and route URLs to each component in your main App.js file:

Home, Procedures, and Contact are all components defined in their own file. In order to route URLs to these components the components need to be be imported at the beginning of the file and referenced in the <Route> elements path={} attribute appropriately.

Notice that the root route, or the index route, at path="/" has an extra attribute called exact. The exact attribute means that the component will only be shown if the URL is exactly equal to that path. If the extra attribute is ommitted then the Home component will be shown on the /procedures and /contact URL routes as well because they start with the slash / too.

import React, { Component } from 'react';
import './App.css';

import Home from './home';
import Procedures from './procedures';
import Contact from './contact';

import {
  BrowserRouter as Router,
  Route,
  Link
} from 'react-router-dom'

class App extends Component {
  render() {
    return (
      <Router>
        <div>
          <nav>
            <ul>
              <li><Link to="/">Home</Link></li>
              <li><Link to="/procedures">Procedures</Link></li>
              <li><Link to="/contact">Contact</Link></li>
            </ul>
          </nav>
          <Route exact path="/" component={Home} />
          <Route path="/procedures" component={Procedures} />
          <Route path="/contact" component={Contact} />
        </div>
      </Router>
    );
  }
}

export default App;

Licensing

All content is licensed under a CC­BY­NC­SA 4.0 license. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

react-router-simple-dentist-site's People

Contributors

geluso avatar

Stargazers

James avatar

Watchers

 avatar James Cloos avatar  avatar

react-router-simple-dentist-site's Issues

Module.export ???

I see module.export is used on the Contact and Procedure files. Not sure if there was a reason for this, but using the code as it is here made me have errors. I used export default instead and things worked fine.

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.