How to use the react-router-dom.useLocation function in react-router-dom

To help you get started, we’ve selected a few react-router-dom 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 alexieyizhe / intern.plus / src / utils / analytics.ts View on Github external
const Analytics: React.FC = () => {
  const location = useLocation();

  /**
   * Track each navigation to a page.
   */
  useEffect(() => {
    ReactGA.set({ page: location.pathname });
    ReactGA.pageview(location.pathname);
  }, [location.pathname]);

  // don't actually render anything
  return null;
};
github Mines-Paristech-Students / Portail-des-eleves / frontend / src / utils / useURLState.tsx View on Github external
export function useURLState(
  paramToWatch: string,
  defaultValue: T,
  toUrlConverter: (data: T) => string = JSON.stringify,
  fromUrlConverter: (data: string) => T = JSON.parse
): [T, (T) => void] {
  const location = useLocation();
  const [paramValue, setParamValue] = useState(defaultValue);

  const changeParam = (value) => {
    // No change, don't do anything
    if (value === paramValue) {
      return;
    }

    setParamValue(value);

    // Change URL value
    const params = new URLSearchParams(
      // substr removes the hash tag at the beginning
      new URL(window.location.href).hash.substr(1)
    );
    const urlValue = toUrlConverter(value);
github opctl / opctl / webapp / src / components / FsHasEntry / index.tsx View on Github external
export default function FsHasEntry(
  {
    fsEntry,
    style
  }: Props
) {
  const [isOpen, setIsOpen] = useState(false)
  const { openWindow } = useContext(WindowContext)
  const location = useLocation()
  const urlSearchParams = new window.URLSearchParams(location.search)
  const mount = urlSearchParams.get('mount')

  useEffect(
    () => {
      if (mount && mount.length >= fsEntry.path.length) {
        setIsOpen(true)
      }
    },
    [
      mount,
      fsEntry
    ]
  )

  return (
github Fairshots / Fairshots.org / src / components / main.js View on Github external
export default function Main(props) {
    const { pathname } = useLocation();

    useEffect(
        () => {
            window.scrollTo(0, 0);
        },
        [pathname]
    );

    return (
        <main>
            </main>
github alexieyizhe / intern.plus / src / components / Card / ReviewCard / index.tsx View on Github external
className,
  heading,
  subheading,
  rating,
  color,
  linkTo,
  tags,
  children,
  ...rest
}) =&gt; {
  /**
   * Go to review page while setting state
   * so that the current page now becomes the
   * background for the review modal.
   */
  const location = useLocation();
  const linkToWithState = useMemo(
    () =&gt; ({
      pathname: linkTo,
      state: {
        background: location,
      },
      search: location.search,
    }),
    [linkTo, location]
  );

  return (
github VNG-Realisatie / nlx / management-ui / src / pages / LoginPage / index.js View on Github external
function useLoginErrorMessage() {
  const { t } = useTranslation()
  const loc = useLocation()

  const match = loc.hash.match(/#auth-(.*)/)

  if (match === null) {
    return null
  }

  switch (match[1]) {
    case 'fail':
      return t('Something went wrong when logging in. Please try again.')

    case 'missing-user':
      return t("User doesn't exist in NLX Management.")

    default:
      return null
github VNG-Realisatie / nlx / management-ui / src / pages / services / ServiceDetailPage / ServiceDetailView / index.js View on Github external
const ServiceDetailView = ({ service, removeHandler }) =&gt; {
  const { internal, inways } = service
  const { t } = useTranslation()
  const location = useLocation()

  const [ConfirmRemoveModal, confirmRemove] = useConfirmationModal({
    okText: t('Remove'),
    children: <p>{t('Do you want to remove the service?')}</p>,
  })

  const handleRemove = async () =&gt; {
    if (await confirmRemove()) {
      removeHandler()
    }
  }

  return (
    &lt;&gt;
      {showServiceVisibilityAlert({ internal, inways }) ? (
github onitsoft / nexchange-open-client-react / src / services / intercom.js View on Github external
export const Intercom = (props) => {
  const location = useLocation()
  const { pathname, search } = location

  useEffect(() => {
    window.Intercom("boot", { app_id })
  }, [])

  useEffect(() => {
    window.Intercom("update")
  }, [pathname, search])

  return null
}
github bestofjs / bestofjs-webui / src / components / search / SearchProvider.js View on Github external
export const SearchProvider = ({ children }) => {
  const location = useLocation()
  const history = useHistory()

  const { query, selectedTags, page, sort } = queryStringToState(
    location.search
  )

  const onChange = changes => {
    const queryString = stateToQueryString({
      query,
      selectedTags,
      page: 1,
      sort,
      ...changes
    })

    history.push({
github smartcontractkit / chainlink / feeds / src / pages / Custom.tsx View on Github external
const Page: React.FC = ({
  config,
  fetchOracleNodes,
  storeAggregatorConfig,
}) =&gt; {
  const location = useLocation()

  useEffect(() =&gt; {
    storeAggregatorConfig(parseConfig(parseQuery(location.search)))
  }, [storeAggregatorConfig, location.search])

  useEffect(() =&gt; {
    fetchOracleNodes()
  }, [fetchOracleNodes])

  let content

  if (config &amp;&amp; config.contractVersion === 3) {
    content = 
  } else if (config) {
    content = 
  } else {