How to use the react-router-dom.useRouteMatch 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 3scale / porta / portafly / src / components / AppNavExpandable.tsx View on Github external
export const AppNavExpandable: React.FunctionComponent = ({
  title,
  to,
  items
}) => {
  const match = useRouteMatch({
    path: to
  })
  const isActive = !!match
  return (
    
      {items.map((item, j) => (
        // FIXME: each app-nav-item should have a fixed ID, using title? or j is just a dirty trick
        
      ))}
    
  )
}
github neinteractiveliterature / intercode / app / javascript / NotificationAdmin / NotificationConfiguration.jsx View on Github external
function NotificationConfiguration() {
  const match = useRouteMatch();
  const history = useHistory();
  const category = NotificationsConfig.categories.find((c) => c.key === match.params.category);
  const event = category.events.find((e) => e.key === match.params.event);

  const { data, loading, error } = useQuery(NotificationAdminQuery);
  const [updateMutate] = useMutation(UpdateNotificationTemplate);
  const [
    updateNotificationTemplate, updateError, updateInProgress,
  ] = useAsyncFunction(updateMutate);

  const eventKey = `${category.key}/${event.key}`;

  const initialNotificationTemplate = (
    loading || error
      ? null
      : data.convention.notification_templates
github ZupIT / horusec / horusec-manager / src / pages / External / Auth / Horusec / Login / index.tsx View on Github external
function LoginScreen() {
  const { t } = useTranslation();
  const history = useHistory();
  const { path } = useRouteMatch();
  const { login, loginInProgress } = useAuth();
  const { disabledBroker } = getCurrentConfig();

  const [email, setEmail] = useState({ value: '', isValid: false });
  const [password, setPassword] = useState({
    value: '',
    isValid: false,
  });

  const handleSubmit = (event: FormEvent) => {
    event.preventDefault();

    if (email.isValid && password.isValid) {
      login({ username: email.value, password: password.value }).then(() => {
        history.replace('/home');
      });
github OriginProtocol / origin / dapps / shop / src / pages / admin / order / Printful.js View on Github external
const Printful = () => {
  const { config } = useConfig()
  const [create, setCreate] = useState(false)
  const [confirm, setConfirm] = useState(false)
  const match = useRouteMatch('/admin/orders/:orderId/:tab?')
  const { orderId } = match.params
  const { order, loading } = useOrder(orderId)
  const { printfulIds } = usePrintfulIds()
  const printfulOrder = usePrintful(orderId)
  const [{ admin }] = useStateValue()

  if (loading) {
    return <div>Loading...</div>
  }
  if (!order) {
    return <div>Order not found</div>
  }

  const printfulData = generatePrintfulOrder(order, printfulIds)

  if (printfulOrder) {
github OriginProtocol / origin / dapps / shop / src / pages / admin / order / Order.js View on Github external
const AdminOrder = () =&gt; {
  const match = useRouteMatch('/admin/orders/:orderId/:tab?')
  const { orderId } = match.params
  const { order, loading } = useOrder(orderId)
  const urlPrefix = `/admin/orders/${orderId}`

  if (loading) {
    return 'Loading...'
  }
  if (!order) {
    return 'Order not found'
  }
  const cart = order.data
  return (
    &lt;&gt;
      {!cart.offerId ? null : <h3>{`Order #${cart.offerId}`}</h3>}
      <ul>
        <li></li></ul>
github ZupIT / horusec / horusec-manager / src / pages / Internal / index.tsx View on Github external
function InternalRoutes() {
  const { path } = useRouteMatch();
  const { isAdminOfWorkspace } = useWorkspace();

  return (
github penta-jelly / re-radio / client / src / modules / station / playlist / index.tsx View on Github external
export const Playlist: React.FC = () =&gt; {
  const classes = useStyles();

  const match = useRouteMatch();
  if (!match) {
    throw new Error(`Match not found. Do you $stationSlug is not existed in query param.`);
  }

  const { loading, error, data, updateQuery } = useStationPlaylistQuery({
    variables: { stationSlug: match.params.slug },
    fetchPolicy: 'network-only',
  });

  useOnStationPlaylistChangedSubscription({
    variables: { stationSlug: match.params.slug },
    onSubscriptionData: ({ subscriptionData: { data } }) =&gt; {
      if (!data) return;
      const { onPlaylistSongChanged } = data;
      if (!onPlaylistSongChanged) return;
      const { entity } = onPlaylistSongChanged;
github 3scale / porta / portafly / src / components / SwitchWith404.tsx View on Github external
export const SwitchWith404: React.FunctionComponent = ({
  children
}) =&gt; {
  const match = useRouteMatch()
  const defaultMatch = React.useMemo(
    () =&gt; match &amp;&amp; ,
    [match]
  )
  return (
github kalmhq / kalm / frontend / src / pages / Domains / Config.tsx View on Github external
const DomainConfigPageRaw: React.FC = () =&gt; {
  const dispatch = useDispatch();
  const { domains, isLoading, isFirstLoaded, certificates, acmeServer } = useSelector((state: RootState) =&gt; {
    return {
      isLoading: state.domains.isLoading,
      isFirstLoaded: state.domains.isFirstLoaded,
      domains: state.domains.domains,
      certificates: state.certificates.certificates,
      acmeServer: state.certificates.acmeServer,
    };
  });

  const router = useRouteMatch&lt;{ name: string }&gt;();
  const domain = domains.find((x) =&gt; x.name === router.params.name);

  if (isLoading &amp;&amp; !isFirstLoaded) {
    return ;
  }

  if (!domain) {
    return no such domain;
  }

  const isWildcard = domain.domain.startsWith("*");

  let cert: Certificate | undefined;

  cert = certificates.find((x) =&gt; x.domains.length === 1 &amp;&amp; x.domains[0] === domain.domain);
  if (!cert) {
github react-spring / react-three-fiber / examples / pages / Intro.js View on Github external
function Demos() {
  let match = useRouteMatch('/demo/:name')
  let { bright } = visibleComponents[match ? match.params.name : defaultComponent]
  return (
    
      {Object.entries(visibleComponents).map(([name, item]) =&gt; (