let { mobileSidebarOpen } = this.state; let sections = extractSections(Content); let section = sections.find(({ url }) => location.pathname.startsWith(url)); let pages = extractPages(Content); const sidebarPages = this._strip( return ( <div className="site"> <DocumentTitle title={getPageTitle(Content, location.pathname)} /> <div className="site__header"> <NotificationBar /> <Navigation pathname={location.pathname} toggleSidebar={this._toggleSidebar} links={[ <Route exact strict path="/:url*" render={props => <Redirect to={`${props.location.pathname}/`}/>} /> <Route path="/" exact component={Splash} /> <Route <Sidebar className="site__sidebar" currentPage={location.pathname} pages={sidebarPages} />
}, [location.pathname]);
/** The current relative URL (pathname + search + hash). */ get locationURL() { const loc = _history.location; return loc.pathname + loc.search + loc.hash; }
test("Nav - successfully navigates around", () => { const history = createMemoryHistory(); const { getByText } = render( <Router history={history}> <Nav /> </Router> ); fireEvent.click(getByText(/about/i)); expect(history.location.pathname).toBe("/about"); });
function checkToken() { if (!getCookie(cookie.token) && history.location.pathname !== '/login') { // 提示信息失效请登录 history.push('/login') } }
checkCredentials(){ AppDispatcher.dispatch({ type: MenuActionTypes.GAME_LOAD_DATA_START }); const data = { room: History.location.pathname.substr(6), player: Socket.getSocket().id }; Socket.getSocket().emit("/game/start/check", data); }
export default function NotFound() { const location = useLocation(); return ( <Flexbox alignItems='center' flexDirection='column'> <S.ErrorCode>404</S.ErrorCode> <S.Text> No match for <code>{location.pathname}</code> </S.Text> <ButtonSecondary as={Link} to='/'>Back home</ButtonSecondary> </Flexbox> ); }
const AuthenticatedRoute = ({ component: Component, ...rest }) => ( <Route {...rest} render={props => rest.isAuthenticated ? ( <Component {...props} /> ) : ( <Redirect to={`/login?redirect=${props.location.pathname}`} /> ) } /> )
componentDidMount() { let sampleIndex = samples.indexOf( samples.find((sample) => sample.path === this.history.location.pathname) ); sampleIndex = Math.max(0, sampleIndex); this.setTitle(samples[sampleIndex].name); }
history.listen((location, action) => { if(location.pathname === "/") Socket.getSocket().emit("/hall/exit", true); });
function NoMatch() { let location = useLocation(); return ( <div> <h3> No match for <code>{location.pathname}</code> </h3> </div> ); }
const redirectMiddleware = store => next => (action) => { const refreshTokenExpiration = token.getRefreshTokenExpiration(); const isExpired = Date.now() > refreshTokenExpiration || !refreshTokenExpiration; if(isExpired && history.location.pathname !== '/signin') { history.push('/signin'); return; } if(action) { next(action); } return; }
checkCredentials(){ AppDispatcher.dispatch({ type: MenuActionTypes.HALL_LOAD_DATA_START }); const data = { room: History.location.pathname.substr(6), player: Socket.getSocket().id }; Socket.getSocket().emit("/hall/join-room/check", data); }
test("About - navigate to users page", () => { const history = createMemoryHistory(); const { getByText } = render( <Router history={history}> <About /> </Router> ); fireEvent.click(getByText("Go to User Page")); expect(history.location.pathname).toBe("/users"); });
componentDidMount() { let sampleIndex = samples.indexOf( samples.find((sample) => sample.path === this.history.location.pathname) ); sampleIndex = Math.max(0, sampleIndex); this.setTitle(samples[sampleIndex].name); }