How to use react-router - 10 common examples

To help you get started, we’ve selected a few react-router examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github percolatestudio / percolatestudio.com / app / components / Routes.jsx View on Github external
var How = require("./How");
var What = require("./What");
var Product = require("./Product");
var Careers = require("./Careers");
var Job = require("./Job");
var NotFound = require("./NotFound");
var StyleguideBase = require("./styleguide/Base");
var StyleguideCaseStudy = require("./styleguide/CaseStudy");

// The eslint config below is needed for a jsx block that exists outside a
// React.CreateElement

/* eslint-disable no-unused-vars */
var React = require("react");
var Route = Router.Route;
var DefaultRoute = Router.DefaultRoute;
var NotFoundRoute = Router.NotFoundRoute;
/*eslint-enable no-unused-vars */

/* eslint-disable no-undef */
var routes = (
github department-of-veterans-affairs / vets-website / test / hca / routes.unit.spec.jsx View on Github external
describe('renders correct component', () => {
    const history = createMemoryHistory('/');
    const store = createStore(veteran);
    let tree;

    before(() => {
      // It's perfectly fine in this test to reuse the rendered component. Do that
      // cause it cuts the test time from 1s down to ~0.1s.
      tree = SkinDeep.shallowRender((
        
          
            {routes}
          
        
        ), {
          store // Mock the Redux store context so components render.
        }
      );
github mozilla / learning.mozilla.org / lib / routes.jsx View on Github external
var React = require('react');

var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var IndexRedirect = ReactRouter.IndexRedirect;
var Route = ReactRouter.Route;
var Redirect = ReactRouter.Redirect;
var IndexRoute = ReactRouter.IndexRoute;
var config = require('../config/config');
var SUPPORTED_LOCALES = config.SUPPORTED_LOCALES;
var MAKER_PARTY_LOCALES = config.MAKER_PARTY_LOCALES;


// verify we have at least one locale
if (SUPPORTED_LOCALES.length === 0) {
  console.error("No locales were loaded into routes.jsx, no routes can be built!");
  process.exit(1);
}
github kinectus / connectus / client / js / components / outletsListMap.js View on Github external
}
        });
        console.log(that.state.userLocation);
      });
    } 
  },

  getInitialState: function(){
    return {
      outletData: [],
      outletTable: 'hello',
      userLocation: {}
    };
  },
  
  mixins: [Router.Navigation], //makes the router navigation information available for use (need this for redirection)
  
  componentDidMount: function() {
    this.getLocation();
    FooterCheck.checker();
    var that = this;
    // TODO: change function so that it retrieves only outlets near users location
    outletStore.getOutlets().then(function(outletData){
      outletData.map(function(outlet){
        userStore.getUsernameById(outlet.id).then(function(user){
          console.log(user.username)
          outlet['seller'] = user.username;
          that.setState({outletData: outletData});
        });
      });
    });
  },
github jaredpalmer / razzle / server / server.js View on Github external
server.get('*', (req, res) => {
  const store = configureStore({
    sourceRequest: {
      protocol: req.headers['x-forwarded-proto'] || req.protocol,
      host: req.headers.host
    }
  })
  const routes = createRoutes(store)
  const history = createMemoryHistory(req.originalUrl)
  const { dispatch } = store

  match({ routes, history}, (err, redirectLocation, renderProps) => {
    if (err) {
      console.error(err)
      return res.status(500).send('Internal server error')
    }

    if (!renderProps) {
      return res.status(404).send('Not found')
    }

    const { components } = renderProps

    // Define locals to be provided to all lifecycle hooks:
    const locals = {
github Playing-Indoors / KDM_WWW / src / scenes / Survivor / containers / DeathRecord.jsx View on Github external
handleClose() {
    browserHistory.push(
      `/settlements/${this.props.params.oid}/survivors/${this.props.params
        .survivorId}`
    );
  }
  // Handle's the save and makes the API Call
github inkdrop-network / inkdrop-app / src / user / userSagas.js View on Github external
// update store
      yield put({
        type: USER_LOGGED_IN,
        payload: newUser,
      })
      // change route to newsfeed (or to redirect url)
      let currentLocation = browserHistory.getCurrentLocation()

      if ('redirect' in currentLocation.query) {
        yield browserHistory.push(decodeURIComponent(currentLocation.query.redirect))
      } else {
        yield browserHistory.push('/newsfeed')
      }
    } catch (error) {}
  } else {
    yield browserHistory.push('/signup')
  }
}
github november9 / wecansavedemocracy / src / containers / ActivitiesNew / individual_activity.js View on Github external
addActivity(activityData) {
    if (activityData.acf.special_content !== 'findrep' && activityData.acf.special_content !== 'elections') {
      this.props.addUserActivity(activityData);
      browserHistory.push('/');
    } else {

      switch (activityData.acf.special_content) {
        case 'findrep':
          this.props.lookForReps(activityData);
          browserHistory.push('/find-representative');
          break;
        case 'elections':
          // do something
          break;
        default:
        // do something by default
      }
    }
  }
github numenta / numenta-web / packages / numenta.com / pages / press / releases.jsx View on Github external
_yearChanged(event) {
    // Reset postion to first page when changing the year
    const year = parseInt(event.target.value, 0)
    const state = Object.assign({}, this.state, {position: 0, year})
    this.setState(state)

    // Update history to include the new state
    const {location} = this.props
    const {key, pathname, query, hash} = location
    browserHistory.push({
      key, pathname, query, hash, state,
    })
  }
github alpcanaydin / heygidi / app / src / components / Year.js View on Github external
loadData(year) {
    if (this.state.years.indexOf(parseInt(year, 10)) === -1) {
      hashHistory.push('/');
      return;
    }

    /* eslint-disable */
    const data = require(`../data/${year}.json`);
    /* eslint-enable */

    this.setState({
      loading: false,
      data: dataTransformer(data)
    });
  }