react-router-dom#BrowserRouter JavaScript Examples

The following examples show how to use react-router-dom#BrowserRouter. 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 course-manager with MIT License 7 votes vote down vote up
// ----------------------------------------------------------------------

ReactDOM.render(
  <HelmetProvider>
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </HelmetProvider>,
  document.getElementById('root')
);
Example #2
Source File: headerBody.jsx    From Oud with MIT License 6 votes vote down vote up
render(){
    if (this.state.redirect) {
      return <Redirect to={this.state.redirect} />;
    }
  return (
    <BrowserRouter>
    <div data-testid="HeaderBody">
      <h2 data-testid="title" className="gray-text likedSongsTitle">
        Liked Songs
      </h2>
      <button
        data-testid="owner"
        className="playlistAnchor songButton block"
        onClick={() => {
          this.redirect(`/profile/${this.state.id}`)
        }}
      >
      {this.state.displayName}
      </button>
      <button
        onClick={()=>this.handlePlayClick}
        data-testid="playButton"
        className="playButton"
        variant="outline-success"
      >
        {this.props.playing ? "PAUSE" : "PLAY"}
      </button>
      <p className="likedSongsTitle gray-text">
        <span data-testid="songsNumber">{this.props.length} </span>
        <span data-testid="songsLiteral">{this.props.length > 1 ? "songs" : "song"}</span>
      </p>
    </div>
    </BrowserRouter>
  );
      
}
Example #3
Source File: App.js    From tisn.app with GNU Affero General Public License v3.0 6 votes vote down vote up
App = () => (
  <BrowserRouter>
    <UserProvider>
      <NotificationsProvider>
        <ThemeProvider>
          <ConfirmProvider>
            <Suspense fallback={<LinearProgress />}>
              <CssBaseline />
              <Navigation />
            </Suspense>
          </ConfirmProvider>
        </ThemeProvider>
      </NotificationsProvider>
    </UserProvider>
  </BrowserRouter>
)
Example #4
Source File: App.js    From pokedex-old with MIT License 6 votes vote down vote up
// const Pokedex = React.lazy(() => import("./pages/Pokedex"));
// const Home = React.lazy(() => import("./pages/Home"));
// const Pokemon = React.lazy(() => import("./pages/Pokemon"));

function App() {
  return (
    <BrowserRouter>
      <div style={{ backgroundColor: "#fff" }}>
        <Route path="/" exact component={Pokedex} />
        <Route path="/pokedex" exact component={Pokedex} />
        <Route path="/pokemon/:pokemonIndex" exact component={Pokemon} />
      </div>
    </BrowserRouter>
  );
}
Example #5
Source File: MyRoutes.test.js    From viade_en1b with MIT License 6 votes vote down vote up
beforeEach(() => {
  const { container, rerender } = render(
    <IntlProvider key={"en"} locale={"en"} messages={locales["en"]}>
      <BrowserRouter>
        <MyRoutes></MyRoutes>
      </BrowserRouter>
    </IntlProvider>
  );
  myRoutes = container;
  rerenderFunc = rerender;
});
Example #6
Source File: MusicHome.jsx    From Music-Hoster-FrontEnd-Using-React with MIT License 6 votes vote down vote up
render() {
    return (
        
        <BrowserRouter>
        <Navbar2/>
        <Switch>
            
            <Route path="/MusicData" component={MusicData}/>
            <Route path="/" component={MusicUploader}/>
        </Switch>
        </BrowserRouter>
    );
  }
Example #7
Source File: index.js    From Alternative-Uniswap-Interface with GNU General Public License v3.0 6 votes vote down vote up
ReactDOM.render(
  <BrowserRouter>
    <React.StrictMode>
      <App />
    </React.StrictMode>
  </BrowserRouter>,

  document.getElementById("root")
);
Example #8
Source File: index.js    From connect-4-online-multiplayer with MIT License 6 votes vote down vote up
ReactDOM.render(
  <React.StrictMode>
    <BrowserRouter>
      <UserProvider>
        <App />
      </UserProvider>
    </BrowserRouter>
  </React.StrictMode>,
  document.getElementById("root")
);
Example #9
Source File: index.js    From Merch-Dropper-fe with MIT License 6 votes vote down vote up
ReactDOM.render(
  <Provider store={store}>
    <BrowserRouter history={history}>
      <PersistGate persistor={persistor}>
        <Auth0Provider
          domain={config.domain}
          client_id={config.clientId}
          redirect_uri={window.location.origin}
          audience={config.audience}
          onRedirectCallback={onRedirectCallback}
        >
          <App />
        </Auth0Provider>
      </PersistGate>
    </BrowserRouter>
  </Provider>,
  document.getElementById("root")
);
Example #10
Source File: index.js    From foster-together-fe with MIT License 6 votes vote down vote up
renderWithReduxAndRouter = ui => {
  return {
    ...render(
      <Provider store={store}>
        <ThemeProvider theme={theme}>
          <BrowserRouter>{ui}</BrowserRouter>
        </ThemeProvider>
      </Provider>
    ),
    store,
  }
}
Example #11
Source File: LandingPage.test.js    From grants-fe with MIT License 6 votes vote down vote up
describe("LandingPage has buttons", () => {
  test("LandingPage has register button", () => {
    const { getByText } = renderRedux(
      <BrowserRouter>
        <LandingPage />
      </BrowserRouter>,
      {
        initialReducerState: {},
      }
    );
    expect(getByText(/Register/i)).toBeVisible();
  });
  test("LandingPage has login button", () => {
    const { getByText } = renderRedux(
      <BrowserRouter>
        <LandingPage />
      </BrowserRouter>,
      {
        initialReducerState: {},
      }
    );
    expect(getByText(/login/i)).toBeVisible();
  });
});
Example #12
Source File: App.test.js    From neighborhood-chef-fe with MIT License 6 votes vote down vote up
it("renders without crashing", () => {
  const div = document.createElement("div");
  ReactDOM.render(
    <Provider store={store}>
      <BrowserRouter>
        <App />
      </BrowserRouter>
    </Provider>,

    div
  );
});
Example #13
Source File: App.js    From schematic-capture-fe with MIT License 6 votes vote down vote up
App = () => {
  const dispatch = useDispatch()
  const { isLoading, error } = useSelector(state => state.app)

  useEffect(() => {
    if (!!error) {
      alert(error);
      dispatch({type : actions.RESET_ERROR})
    }
  }, [error])

  return (
    <>
      {isLoading && <PageLoader />}
      <BrowserRouter>
        <NormalizeStyles />
        <BaseStyles />
        <Router />
      </BrowserRouter>
    </>
  )
}
Example #14
Source File: AppRouter.js    From social-media-strategy-fe with MIT License 6 votes vote down vote up
function AppRouter() {
  return (
    <BrowserRouter>
      <Switch>
        <Route exact path="/" component={Landing} />
        <Security
          {...oktaConfig}
          onAuthRequired={() => {
            if (window.location.pathname !== "/login") {
              window.location.pathname = "/login";
            }
          }}
        >
          <App />
        </Security>
      </Switch>
    </BrowserRouter>
  );
}
Example #15
Source File: App.test.js    From workout-tracker-fe-pt with MIT License 6 votes vote down vote up
it("renders without crashing", () => {
  const div = document.createElement("div");
  ReactDOM.render(
    <BrowserRouter>
      <App />
    </BrowserRouter>,
    div
  );
});
Example #16
Source File: DeletionDialog.test.jsx    From Corona-tracker with MIT License 6 votes vote down vote up
describe('DeletionDialog', () => {
  it('should render a DeletionDialog component ', () => {
    const store = mockStore();
    window.HTMLCanvasElement.prototype.getContext = () => {};

    const wrapper = mount(
      <Provider store={store}>
        <BrowserRouter>
          <DeletionDialog
            setShowDeletionDialog={() => {
              return 'test';
            }}
          />
        </BrowserRouter>
      </Provider>
    );
    expect(wrapper.find('DeletionDialog')).toMatchSnapshot();
  });
});
Example #17
Source File: LinkOrExternal.test.jsx    From genshin with MIT License 6 votes vote down vote up
describe('LinkOrExternal', () => {
  it('should contain a "a" for external link', () => {
    render(<LinkOrExternal to={HTTPS_EXTERNAL_LINK}>Test link</LinkOrExternal>);
    expect(screen.getByTestId('external-link-node')).toBeTruthy();
  });

  it('should contain a Link component for internal link', () => {
    render(
      <BrowserRouter>
        <LinkOrExternal to={INTERNAL_LINK}>Test link</LinkOrExternal>
      </BrowserRouter>,
    );
    expect(screen.getByTestId('internal-link-node')).toBeTruthy();
  });
});
Example #18
Source File: index.js    From cm-fe-developer-task with MIT License 6 votes vote down vote up
ReactDOM.render(
  <BrowserRouter>
    <Switch>
      <Route path="/admin" component={Admin} />
      <Redirect from="/" to="/admin/dashboard" />
    </Switch>
  </BrowserRouter>,
  document.getElementById("root")
);
Example #19
Source File: index.js    From react-firebase-admin with MIT License 6 votes vote down vote up
RouterComponent = () => {
  return (
    <BrowserRouter>
      <Switch>
        <Route exact path={paths.LOGIN} component={Login} />
        <Route exact path={paths.RESET_PASSWORD} component={ResetPassword} />
        <PrivateRoute path={paths.ADD_USER} component={User} />
        <PrivateRoute path={paths.MODIFY_USER} component={User} />
        <PrivateRoute path={paths.USERS} component={Users} />
        <PrivateRoute path={paths.PROFILE} component={Profile} />
        <PrivateRoute path={paths.SECTION} component={Section} />
        <PrivateRoute path={paths.SUBMENU_1} component={Submenu} />
        <PrivateRoute path={paths.SUBMENU_2} component={Submenu} />
        <PrivateRoute path={paths.ROOT} component={Home} />
        <Route component={NotFound} />
      </Switch>
    </BrowserRouter>
  );
}
Example #20
Source File: index.js    From airdnd-frontend with MIT License 6 votes vote down vote up
ReactDOM.render(
  <Provider store={store}>
    <BrowserRouter>
      <ThemeProvider theme={theme}>
        <App />
      </ThemeProvider>
    </BrowserRouter>
  </Provider>,
  document.getElementById('root'),
);
Example #21
Source File: App.js    From roomie-frontend with MIT License 6 votes vote down vote up
App = () => {
  const { userId } = useContext(Context);
  const { isHost } = useContext(Context);
  const isLogged = userId && (isHost !== null);
  const isLoggedHost = isLogged && isHost;

  return (
    <BrowserRouter>
      <GlobalStyle />
      <Switch>
        <Route exact path='/' component={isLogged ? Home : Signin} />
        <Route exact path='/signin' component={isLogged ? Home : Signin} />
        <Route exact path='/signup' component={isLogged ? Home : Signup} />
        <Route exact path='/create/place' component={isLoggedHost ? CreatePlace : Home} />
        <Route exact path='/create/profile' component={isLogged ? Home : CreateProfile} />
        <Route exact path='/places/:placeId' component={isLogged ? ViewRoom : Signin} />
        <Route exact path='/favorites' component={isLogged ? Favorites : Signin} />
        <Route exact path='/profile/:profileId' component={ViewProfile} />
        <Route component={NotFound} />
      </Switch>
    </BrowserRouter>
  );
}
Example #22
Source File: App.js    From Official-Website with MIT License 6 votes vote down vote up
render() {
        return (
            <Provider store={store}>
                <BrowserRouter>
                    <HomeRoutes/>
                </BrowserRouter>
            </Provider>
        );
    }
Example #23
Source File: routes.js    From SemanaOmnistack11 with MIT License 6 votes vote down vote up
export default function Routes() {
  return (
    <BrowserRouter>
      <Switch>
        <Route path="/" component={Logon} exact />
        <Route path="/register" component={Register} exact />
        <Route path="/profile" component={Profile} exact />
        <Route path="/incidents/new" component={NewIncident} exact />
      </Switch>
    </BrowserRouter>
  );
}
Example #24
Source File: index.js    From astra-tik-tok with Apache License 2.0 6 votes vote down vote up
App = () => {
  
  return (
    <BrowserRouter>
      <Header />
    <Routes>
      <Route path= "/upload" element={<Upload />}/>
      <Route path= "/" element={<Home />}/>
    </Routes>
  </BrowserRouter>
  )
}
Example #25
Source File: App.js    From thedesignsystems with MIT License 6 votes vote down vote up
function App() {
  return (
    <div className="center__view App">
      {/* header component */}
      <Header />

      <BrowserRouter>
        <Route path="/" exact component={LandingPage} />
        <Route path="/team" exact component={Team} />
        <Route path="/products" exact component={Products} />
        <Route path="/careers" exact component={Careers} />
        <Route path="/contact-us" exact component={ContactUs} />
        {/* routes for re-direction to external links */}
        <Route path="/discord" exact component={Discord} />
        <Route path="/twitter" exact component={Twitter} />
        <Route path="/github" exact component={GitHub} />
        <Route path="/linkedin" exact component={LinkedIn} />
        <Route path="/yash" exact component={() => PersonalLinks('yash')} />
      </BrowserRouter>
      {/* footer component */}
      <Footer />
    </div>
  );
}
Example #26
Source File: routes.js    From React-Messenger-App with MIT License 6 votes vote down vote up
makeMainRoutes = () => {
    return (
      <BrowserRouter history={history} component={App}>
          <div>
            {/* '/' route*/}
            <Route path="/" render={(props) => <App auth={auth} {...props} />} />
            {/* 'Homepage' route*/}
            <Route path="/home" render={(props) => <Home auth={auth} {...props} />} />
            {/* 'Chat' route*/}
            <Route path="/chat" render={(props) => (
              !auth.isAuthenticated() ? (
                <Redirect to="/home"/>
              ) : (
                <Chat auth={auth} {...props} />
              )
            )} />
            {/* 'Profile' route*/}
            <Route path="/profile" render={(props) => (
              !auth.isAuthenticated() ? (
                <Redirect to="/home"/>
              ) : (
                <Profile auth={auth} {...props} />
              )
            )} />
            {/* 'Callback' route*/}
            <Route path="/callback" render={(props) => {
              handleAuthentication(props);
              return <Callback {...props} />
            }}/>        
          </div>
        </BrowserRouter>
    );
  }
Example #27
Source File: App.js    From ChronoFactorem with GNU General Public License v3.0 6 votes vote down vote up
App = () => {
  // Restore user information on refresh
  useEffect(() => {
    store.dispatch(loadUser());
  }, []);
  return (
    <Provider store={store}>
      <BrowserRouter history={history}>
        <Navbar />
        <Route exact path='/' component={Landing} />
        <Route exact path='/checkloggedin' component={CheckLoggedIn} />
        <SemiPrivateRoute exact path='/helform' component={HelForm} />
        <PrivateRoute exact path='/Dashboard' component={Dashboard} />
        <PrivateRoute exact path='/helData' component={HELData} />
        <PrivateRoute exact path='/create' component={CreateTimeTable} />
        <PrivateRoute exact path='/aboutUs' component={About} />
      </BrowserRouter>
    </Provider>
  );
}
Example #28
Source File: routes.js    From be-the-hero with MIT License 6 votes vote down vote up
export default function Routes() {
  return (
    <BrowserRouter>
      <Switch>
        <Route path="/" exact component={Logon} />
        <Route path="/register" component={Register} />
        <Route path="/profile" component={Profile} />
        <Route path="/incidents/new" component={NewIncident} />
      </Switch>
    </BrowserRouter>
  );
}
Example #29
Source File: routes.js    From OSC-Legal with MIT License 6 votes vote down vote up
Routes = () => (
	<BrowserRouter>
		<Switch>
			<Route exact path='/' component={Login} />
			<Route path='/createfisicalperson' component={CreateFisicalPerson} />
			<Route path='/createlegalperson' component={CreateLegalPerson} />
			<Route component={NoMatch} />
			{/* <PrivateRoute component = {Dashboard} /> */}
		</Switch>
	</BrowserRouter>
)