react-router-dom#Router JavaScript Examples

The following examples show how to use react-router-dom#Router. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js    From bunk-manager-mern with MIT License 6 votes vote down vote up
//creating reset
ReactDOM.render(
  <Provider store={store}>
    <Router history={history}>
      <DarkThemeProvider>
        <App />
      </DarkThemeProvider>
    </Router>
  </Provider>,
  document.querySelector("#root")
);
Example #2
Source File: TestingRouter.js    From viade_en1b with MIT License 6 votes vote down vote up
TestingRouter = ({ ComponentWithRedirection, redirectUrl }) => (
  <IntlProvider key={"en"} locale={"en"} messages={locales["en"]}>
    <Router history={history}>
      <Route
        path="/"
        exact={true}
        render={() => <ComponentWithRedirection />}
      />
      <Route
        path={redirectUrl}
        exact={true}
        render={() => <div>{redirectUrl}</div>}
      />
    </Router>
  </IntlProvider>
)
Example #3
Source File: index.js    From fhir-app-starter with MIT License 6 votes vote down vote up
render() {
    const { error, smart, patient } = this.props;
    return (
      <Router history={history}>
        <Helmet />
        <Container style={{ marginTop: '2rem' }}>
          <Grid columns="1" stackable>
            <Grid.Column>
              {error ? <ErrorMessage {...error} /> : null}
              {patient ? <SuccessMessage patient={patient} user={smart.user} /> : null}
              <Grid.Row>
                <Header as="h1">FHIR App Starter</Header>
                <Divider />
              </Grid.Row>

              <Grid.Row>
                <Information />
              </Grid.Row>

              <Grid.Row>
                <Divider />
              </Grid.Row>

              {smart ? (
                <Switch>
                  <Route path="/" exact component={Home} />
                </Switch>
              ) : null}
            </Grid.Column>
          </Grid>
        </Container>
      </Router>
    );
  }
Example #4
Source File: App.jsx    From CyberStateRP with MIT License 6 votes vote down vote up
render() {
        return (
            <Router history={history}>
                <React.Fragment>
                    <Hud />
                    <Phone />
                    <Documents/>
                    <PoliceCerf/>
                    <SpeedoMeter/>
                    <FibCerf/>
                    <SheriffCerf/>
                    <PoliceTablet/>
                    <MedTablet/>
                    <MedicCerf/>
                    <Inventory/>
                    <PlayerMenu/>
                    <BuyCar/>
                </React.Fragment>
            </Router>
        );
    }
Example #5
Source File: RideRequestsCard.spec.js    From carpal-fe with MIT License 6 votes vote down vote up
test("Should Render the request Card component", () => {
    const div = document.createElement("div");
    const Wrapper = ReactDOM.render(
        <Provider store={store}>
            <Router history={customHistory}>
                <RideRequests>
                    <RideRequestsCard />
                </RideRequests>
            </Router>
        </Provider>,
        div
    );
    expect(Wrapper).toBeNull();
});
Example #6
Source File: LandingPage.test.js    From grants-fe with MIT License 6 votes vote down vote up
describe("Login/Register route to correct forms", () => {
  test("Register button routes to RegisterForm", async () => {
    const history = createMemoryHistory();

    const { container, getByText } = renderRedux(
      <Router history={history}>
        <LandingPage />
      </Router>,
      {
        initialReducerState: {},
      }
    );

    expect(container.innerHTML).toMatch("Get help with your grant today!");
    fireEvent.click(getByText(/register/i));
    expect(history.location.pathname).toBe("/RegisterForm");
  });
  test("Login button routes to LoginForm", () => {
    const history = createMemoryHistory();

    const { container, getByText } = renderRedux(
      <Router history={history}>
        <LandingPage />
      </Router>,
      {
        initialReducerState: {},
      }
    );

    expect(container.innerHTML).toMatch("Get help with your grant today!");
    fireEvent.click(getByText(/login/i));
    expect(history.location.pathname).toBe("/LoginForm");
  });
});
Example #7
Source File: orderContents.js    From shopping-cart-fe with MIT License 6 votes vote down vote up
describe('Buyer info', () => {
  test('should render the main wrapper for orderContentsCard', () => {
    const { getByTestId } = render(<OrderContentsCards />);
    expect(getByTestId('orderContentsCardsWrapper')).toBeVisible();
  });
  test('should render the main wrapper for OrderContents', () => {
    const { getByTestId } = render(<OrderContents />);
    expect(getByTestId('orderContentsWrapper')).toBeVisible();
  });

  test('should render the product card', () => {
    const { rerender, getByText } = render(
      <Router history={history}>
        <ProductCard
          inventory={{
            images: [
              'https://res.cloudinary.com/dnsl4nbz4/image/upload/v1592612280/Products/tkb1s2rqc7qwapdhdcde.png',
            ],
            price: 55,
            productId: '5eed55c1028759000473c85b',
            productName: 'Bike',
            quantity: 1,
          }}
        />
      </Router>
    );
  });
});
Example #8
Source File: index.js    From covidzero-frontend with Apache License 2.0 6 votes vote down vote up
ReactDOM.render(
  <Provider store={store}>
    <Router history={history}>
      <GlobalFonts />
      <ThemeProvider theme={theme}>
        <Suspense fallback={<div>Carregando...</div>}>
          <App />
        </Suspense>
      </ThemeProvider>
    </Router>
  </Provider>,
  document.getElementById("root")
);
Example #9
Source File: App.js    From telar-cli with MIT License 6 votes vote down vote up
function App() {

  // Retrieving data from an AJAX request.
  // Remember that the function passed to useEffect will run,
  // after render is fixed on the screen.
  // See https://reactjs.org/docs/hooks-reference.html#useeffect
  useEffect(() => {
  });

  
  return (
    <Router history={browserHistory}>
      <Provider store={store}>
        <ThemeProvider theme={theme}>
          <Master />
          <Routes />
          <AppSnackbar />
          <DialogInfo />
        </ThemeProvider>
      </Provider>
    </Router>
  );
}
Example #10
Source File: App.test.js    From say-their-names-web with MIT License 6 votes vote down vote up
test('renders Home Page', () => {
  const history = createMemoryHistory();
  history.push('/');

  const { getByText } = render(
    <Router history={history}>
      <App />
    </Router>
  );

  expect(getByText(/Delayed justice is injustice/i)).toBeInTheDocument();
});
Example #11
Source File: index.js    From sampo-ui with MIT License 6 votes vote down vote up
render(
  <Provider store={store}>
    <Router history={history}>
      <Suspense
        fallback={
          <div style={{
            width: '100%',
            height: '100%',
            display: 'flex',
            alignItems: 'center',
            justifyContent: 'center'
          }}
          >
            <CircularProgress
              sx={{
                color: layoutConfig.colorPalette.primary.main
              }}
              thickness={5}
            />
          </div>
          }
      >
        <App />
      </Suspense>
    </Router>
    <ReduxToastr
      timeOut={0}
      newestOnTop={false}
      preventDuplicates
      position='top-center'
      transitionIn='fadeIn'
      transitionOut='fadeOut'
    />
  </Provider>,
  document.getElementById('root')
)
Example #12
Source File: App.js    From AzureEats-Website with MIT License 6 votes vote down vote up
render() {
        const { quantity } = this.state;

        const PrivateRoute = ({ component: Component, ...rest }) => (
            <Route {...rest} render={(props) => (
                this.props.userInfo.loggedIn === true
                    ? <Component {...props} {...rest} />
                    : <Redirect to='/' />
            )} />
        )

        return (
            <div className="App">
                <Router history={history}>
                    <Fragment>
                        <DebugHeader />
                        <Header quantity={quantity} />
                        <Route exact path="/" component={Home} />
                        <Route exact path="/list" component={List} />
                        <Route exact path="/list/:code" component={List} />
                        <Route path="/suggested-products-list" component={SuggestedProductsList} />
                        <Route path="/product/detail/:productId" render={(props) => <Detail sumProductInState={this.sumProductInState} {...props} />} />
                        <PrivateRoute path='/coupons' component={MyCoupons} />
                        <PrivateRoute path='/profile' component={Profile} />
                        <PrivateRoute path='/shopping-cart' component={ShoppingCart} ShoppingCart={this.ShoppingCart} quantity={this.state.quantity} />
                        <Footer />
                    </Fragment>
                </Router>
            </div>
        );
    }
Example #13
Source File: index.js    From codeclannigeria-frontend with MIT License 6 votes vote down vote up
ReactDOM.render(
  <Provider store={store}>
    <React.Fragment>
      <Router history={history}>
        <App />
      </Router>
    </React.Fragment>
  </Provider>,
  document.getElementById('root')
);
Example #14
Source File: App.jsx    From react-alert-notifications with MIT License 6 votes vote down vote up
render() {
        return (
            <Router history={history}>
                {/* nav */}
                <div className="container text-center">
                    <Link to="/" className="btn btn-link">Single Alert</Link>
                    <Link to="/multi-alerts" className="btn btn-link">Multiple Alerts</Link>
                </div>

                {/* main app container */}
                <div className="jumbotron p-4">
                    <div className="container text-center">
                        <Alert />
                        <Route exact path="/" component={Home} />
                        <Route path="/multi-alerts" component={MultiAlerts} />
                    </div>
                </div>
            </Router>
        );
    }
Example #15
Source File: App.jsx    From react-hooks-redux-registration-login-example with MIT License 6 votes vote down vote up
function App() {
    const alert = useSelector(state => state.alert);
    const dispatch = useDispatch();

    useEffect(() => {
        history.listen((location, action) => {
            // clear alert on location change
            dispatch(alertActions.clear());
        });
    }, []);

    return (
        <div className="jumbotron">
            <div className="container">
                <div className="col-md-8 offset-md-2">
                    {alert.message &&
                        <div className={`alert ${alert.type}`}>{alert.message}</div>
                    }
                    <Router history={history}>
                        <Switch>
                            <PrivateRoute exact path="/" component={HomePage} />
                            <Route path="/login" component={LoginPage} />
                            <Route path="/register" component={RegisterPage} />
                            <Redirect from="*" to="/" />
                        </Switch>
                    </Router>
                </div>
            </div>
        </div>
    );
}
Example #16
Source File: App.jsx    From react-recoil-jwt-authentication-example with MIT License 6 votes vote down vote up
function App() {
    return (
        <div className="app-container bg-light">
            <Router history={history}>
                <Nav />
                <div className="container pt-4 pb-4">
                    <Switch>
                        <PrivateRoute exact path="/" component={Home} />
                        <Route path="/login" component={Login} />
                        <Redirect from="*" to="/" />
                    </Switch>
                </div>
            </Router>
        </div>
    );
}
Example #17
Source File: App.js    From graphql-sample-apps with Apache License 2.0 6 votes vote down vote up
function App() {
  const classes = useStyles();
  return (
    <div className={classes.root}>
      <CssBaseline />
      <Sidebar>
        <SidebarItem label="Home" icon={HomeIcon} link="/" />
        <SidebarItem label="Settings" icon={SettingsIcon}>
          <SidebarItem label="Metrics" link="/metrics" />
          <SidebarItem label="Add Data" link="/add-data" />
          <SidebarItem label="Generate Data" link="/generate-data" />
        </SidebarItem>
      </Sidebar>
      <Router history={history}>
        <Suspense fallback={<div />}>
          <Switch>
            <Route path="/" exact={true} component={Home} />
            <Route path="/metrics" exact={true} component={Metrics} />
            <Route path="/add-data" exact={true} component={AddData} />
            <Route path="/generate-data" exact={true} component={GenerateData} />
            <Route component={NotFound} />
          </Switch>
        </Suspense>
      </Router>
    </div>
  )
}
Example #18
Source File: index.js    From EMP with MIT License 6 votes vote down vote up
// You can apply multiple middleware.


ReactDOM.render(
  <Router history={ history }>
    <Provider store={store}>
    <App />
    </Provider>
  </Router>,
  document.getElementById('root')
);
Example #19
Source File: index.js    From git-proxy with Apache License 2.0 6 votes vote down vote up
ReactDOM.render(
    <Router history={hist}>
      <Switch>
        <Route path="/admin" component={Admin} />
        <Route path="/login" component={Login} />
        <Redirect from="/" to="/admin/dashboard" />
      </Switch>
    </Router>,
    document.getElementById('root'),
);
Example #20
Source File: App.js    From paper-and-ink with MIT License 6 votes vote down vote up
function App() {
  const [theme, setTheme] = useState('reply');

  return (
    <ThemeContext.Provider value={{ theme, setTheme }}>
      <ThemeProvider>
        <Router history={history}>
          <Routes />
        </Router>
      </ThemeProvider>
    </ThemeContext.Provider>
  );
}
Example #21
Source File: App.js    From git-insights with MIT License 6 votes vote down vote up
export default function App(props) {
  return (
    <AuthProvider>
      <UserProvider>
        <ThemeProvider theme={theme}>
            <Router history={browserHistory}>
              <Routes />
            </Router>
        </ThemeProvider>
      </UserProvider>
    </AuthProvider>
  );
}
Example #22
Source File: setupTests.js    From fred with MIT License 6 votes vote down vote up
global.renderWithRouter = function renderWithRouter(
  ui,
  {
    route = "/",
    history = createMemoryHistory({ initialEntries: [route] })
  } = {}
) {
  return {
    ...render(<Router history={history}>{ui}</Router>),
    history
  };
};
Example #23
Source File: index.js    From crypto-manager with MIT License 6 votes vote down vote up
ReactDOM.render(
  <Router history={hist} baseName={baseURL}>
    <Switch>
      {indexRoutes.map((prop, key) => {
        return <Route path={prop.path} component={prop.component} key={key} />;
      })}
    </Switch>
  </Router>,
  document.getElementById("root")
);
Example #24
Source File: App.js    From Ajo with MIT License 6 votes vote down vote up
App = ()=>{
  return (
    <Router history={history}>
        <React.Suspense fallback={loading}>
          <Routes />
        </React.Suspense>
    </Router>
  );
}
Example #25
Source File: index.js    From aircon with GNU General Public License v3.0 6 votes vote down vote up
//打包时,用的HashRouter并加上了basename,因为放在服务器的二级目录下
ReactDOM.render(
  <Router history={history}>
    <LocaleProvider locale={zh_CN}>
      <Provider {...store}>
        <App />
      </Provider>
    </LocaleProvider>
  </Router>,
  document.getElementById('root')
);
Example #26
Source File: social-links.test.js    From horondi_client_fe with MIT License 6 votes vote down vote up
describe('Social links tests', () => {
  const history = createMemoryHistory();
  let wrapper;

  beforeEach(() => {
    wrapper = render(
      <Router history={history}>
        <SocialLinks {...props} />
      </Router>
    );
  });

  afterEach(() => {
    wrapper = null;
  });

  it('should render social links', () => {
    expect(wrapper).toBeDefined();
  });

  it('should render title', () => {
    const title = wrapper.getByTestId('title');
    expect(title).toBeInTheDocument();
  });
});
Example #27
Source File: App.js    From Dashboard with MIT License 6 votes vote down vote up
function App(props) {
  const {
    user,
    signOut,
    signInWithGoogle,
    signInWithEmailAndPassword,
    createUserWithEmailAndPassword,
  } = props;

  const auth = {
    user,
    accessToken: user ? user.toJSON().stsTokenManager.accessToken : null,
    methods: {
      signOut,
      signInWithGoogle,
      signInWithEmailAndPassword,
      createUserWithEmailAndPassword,
    },
  };

  console.log(auth);

  return (
    <AuthProvider value={auth}>
      <Router history={hist}> 
        <Switch>
          <Route exact path="/dashboard" component={Dashboard} />
          <Route exact path="/" component={LoginPage} />
          <Route exact path="/add-actor" component={AddActor} />
          <Route exact path="/search-page" component={SearchPage} />
          <Route exact path="/registration-page" component={RegistrationPage} />
        </Switch>
       </Router>       
    </AuthProvider>
  );
}
Example #28
Source File: App.js    From SimpleWeather with MIT License 6 votes vote down vote up
App = () => {
    return (
        <Router history={history}>
            <Switch>
                <Route exact path='/SimpleWeather'>
                    <SearchPage/>
                </Route>
                <Route exact path='/SimpleWeather/cities'>
                    <CitiesPage/>
                </Route>
                <Route exact path='/SimpleWeather/cities/:city'>
                    <CityPage/>
                </Route>
                <Route exact path='/SimpleWeather/forecast'>
                    <ForecastPage/>
                </Route>
                <Redirect to='/SimpleWeather'/>
            </Switch>
        </Router>
    );
}
Example #29
Source File: App.js    From front-app with MIT License 6 votes vote down vote up
App = () => {
  const [storeLoaded, setStoreLoaded] = useState(false)

  useEffect(() => {
    const hydrate = create()
    async function hydrateStore() {
      await hydrate('userStore', stores.userStore)
      await hydrate('chatStore', stores.chatStore)
      await hydrate('luckyStore', stores.luckyStore)
    }
    hydrateStore().then(() => setStoreLoaded(true))
  }, [])

  return (
    <Provider {...stores}>
      <Router history={browserHistory}>
        <Route path={'/adminLogin'} component={AdminLoginPage} />
        <Route path={'/admin'} render={() => (getTokenVerification().length > 0 ? <AdminMainPage /> : <Redirect to={'/adminLogin'} />)} />
        {storeLoaded ? (
          <Switch>
            <Route exact path={'/'} component={MainPage} />
            <Route path={'/login'} component={LoginPage} />
            <Route path={'/loginSuccess'} component={LoginSuccessPage} />
            <Route path={'/signup'} component={SignupPage} />
          </Switch>
        ) : null}
      </Router>
    </Provider>
  )
}