/** The current relative URL (pathname + search + hash). */ get locationURL() { const loc = _history.location; return loc.pathname + loc.search + loc.hash; }
const useQueryParam = (paramName, defaultName) => { const query = new URLSearchParams(useQuery()); const param = query.get(paramName) || defaultName; function useQuery() { return new URLSearchParams(useLocation().search); } return param }
history.listen((location, action) => { console.log(`The current URL is ${location.pathname}${location.search}${location.hash}`); console.log(`The last navigation action was ${action}`); });
const FriendlyRoutes = ({ component: Component, ...rest }) => { //console.log(Component) return ( <Route {...rest} render={(props) => ( fakeAuth.isAuthenticated(props) ? props.location.search.indexOf("p=") > 0 ? <Redirect to={{ pathname: '/n/nut', state: { from: props.location }}} /> : <Component {...props} /> //: false ? <Redirect to={{pathname: '/n/accessing', state: { from: props.location }}} /> : <Component {...props} /> : <Redirect to={{ pathname: props.location.search.indexOf("p=") > 0 ? '/n/nut':'/n/login', state: { from: props.location }}} /> )} /> ) }
function useQuery(keys) { const urlQuery = new URLSearchParams(useLocation().search); const result = {}; keys.forEach(k => { result[k] = urlQuery.get(k); }); return result; }
}; const getUsername = () => { return new URLSearchParams(history.location.search).get("uid"); }; if (!connection) {
const GlobalFeedTab = props => { return ( <li className="nav-item"> <NavLink className="nav-link" isActive={ (match, location) => { return !location.search.match(/tab=(feed|tag)/) ? 1 : 0; } } to={{ pathname: "/", search: "?tab=all" }} > Global Feed </NavLink> </li> ); }
const YourFeedTab = props => { if (props.currentUser) { return ( <li className="nav-item"> <NavLink className="nav-link" isActive={ (match, location) => { return location.search.match("tab=feed") ? 1 : 0; } } to={{ pathname: "/", search: "?tab=feed" }} > Your Feed </NavLink> </li> ); } return null; }
<Route> {({ location }) => { const query = new URLSearchParams(location.search); const page = parseInt(query.get("page") || "1", 10);
// A custom hook that builds on useLocation to parse the query string function useQuery() { return new URLSearchParams(useLocation().search); }
const useQuery = () => { return new URLSearchParams(useLocation().search); }
// A custom hook that builds on useLocation to parse the query string function useQuery() { return new URLSearchParams(useLocation().search); }
const useQuery = () => new URLSearchParams(useLocation().search)
const PrivateRoutes = ({ component: Component, ...rest }) => ( <Route {...rest} render={(props) => ( fakeAuth.isAuthenticated(props) ? props.location.search.indexOf("p=") > 0 ? <Redirect to={{ pathname: '/n/nut', state: { from: props.location } }} /> : <Component {...props} /> : <Redirect to={{ pathname: props.location.search.indexOf("p=") > 0 ? '/n/nut':'/n/login', state: { from: props.location } }} /> )} /> )
function useQuery() { return new URLSearchParams(useLocation().search); }