How to use @reach/router - 10 common examples

To help you get started, we’ve selected a few @reach/router 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 reach / router / examples / crud / src / App.js View on Github external
// Fast network always
// slow initial load
// show loading quickly on initial load, don't show top level placeholder on navigation
import React from "react";
import { Router, Link, Redirect, globalHistory } from "@reach/router";
import {
  login,
  getContacts,
  getContact,
  createContact,
  updateContact,
  deleteContact
} from "./utils";
import createContext from "create-react-context";

globalHistory.listen(({ location, action }) => {
  console.log({ location, action });
});

const InvalidateContacts = createContext();
const withInvalidateContacts = Comp => props => (
  
    {invalidate => }
  
);

const NavLink = props => (
   ({
      className: isPartiallyCurrent ? "nav-link active" : "nav-link"
    })}
    {...props}
github broadinstitute / single_cell_portal_core / app / javascript / components / search_xds / HomePageRouter.js View on Github external
export default function useHomePageRouter() {
  const routerLocation = useLocation()
  const homeParams = buildHomeParamsFromQuery(routerLocation.search)

  /** reset to the default view for a study */
  function clearHomeParams() {
    navigate('')
  }

  useEffect(() => {
    // if this is the first render, and there are already genes specified, that means they came
    // from the URL directly
    if (homeParams.genes.length > 0) {
      // logGlobalGeneSearch(homeParams.genes, 'url')
    }
  }, [])
  return { homeParams, updateHomeParams, routerLocation, clearHomeParams }
}
github pavjacko / renative / packages / renative-template-hello-world / src / app.web.js View on Github external
import React from 'react';
import ScreenHome from './screenHome';
import ScreenMyPage from './screenMyPage';
import ScreenModal from './screenModal';
import Menu from './menu';
import { Router, createHistory, LocationProvider } from "@reach/router";
import '../platformAssets/runtime/fontManager';
import createHashSource from 'hash-source';


// listen to the browser history
let source = createHashSource();
let history = createHistory(source);

class App extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
        
        <div>
            <menu>
            
                
                
                
            </menu></div>
github reach / reach-ui / packages / menu-button / examples / with-links.example.js View on Github external
MenuItem
} from "@reach/menu-button";
import {
  Router,
  Link,
  createMemorySource,
  createHistory,
  LocationProvider
} from "@reach/router";
import "@reach/menu-button/styles.css";

export let name = "With Links";

// this is because we're in an iframe and not a
// pushState server inside of storybook
let memoryHistory = createHistory(createMemorySource("/"));

export function Example() {
  return (
    
      
        
        
      
    
  );
}

function Home() {
  return (
    <div>
      <h2>Home</h2></div>
github textileio / desktop / src / Stores / index.ts View on Github external
import { createMemorySource, createHistory } from '@reach/router'
import moment, { utc } from 'moment'
const { remote } = window.require('electron')
import path from 'path'
import URL from 'url-parse'

const DEFAULT_AVATAR = 'https://react.semantic-ui.com/images/wireframe/square-image.png'

export interface Message {
  name: string
  payload?: any
}

export type Screen = 'starting' | 'loading' | 'online' | 'error' | 'onboard' | 'landing'

const source = createMemorySource('/')
const history = createHistory(source)

// tslint:disable-next-line:no-empty-interface
export interface Store {}

export interface ProfileInfo {
  name: string
  avatar: string
  date: string
  address: string
}

export interface AppInfo {
  appId: string
  appName: string
  link: string
github jacobdcastro / personal-site / .cache / production-app.js View on Github external
)}
        
      )
    }
  }

  const { page, location: browserLoc } = window
  if (
    // Make sure the window.page object is defined
    page &amp;&amp;
    // The canonical path doesn't match the actual path (i.e. the address bar)
    __PATH_PREFIX__ + page.path !== browserLoc.pathname &amp;&amp;
    // ...and if matchPage is specified, it also doesn't match the actual path
    (!page.matchPath ||
      !match(__PATH_PREFIX__ + page.matchPath, browserLoc.pathname)) &amp;&amp;
    // Ignore 404 pages, since we want to keep the same URL
    page.path !== `/404.html` &amp;&amp;
    !page.path.match(/^\/404\/?$/) &amp;&amp;
    // Also ignore the offline shell (since when using the offline plugin, all
    // pages have this canonical path)
    !page.path.match(/^\/offline-plugin-app-shell-fallback\/?$/)
  ) {
    navigate(
      __PATH_PREFIX__ + page.path + browserLoc.search + browserLoc.hash,
      { replace: true }
    )
  }

  loader
    .getResourcesForPathname(browserLoc.pathname)
    .then(resources =&gt; {
github gatsbyjs / gatsby / packages / gatsby / cache-dir / find-page.js View on Github external
pages.some(page => {
    let pathToMatch = page.matchPath ? page.matchPath : page.path
    if (matchPath(pathToMatch, trimmedPathname)) {
      foundPage = page
      pageCache[trimmedPathname] = page
      return true
    }

    // Finally, try and match request with default document.
    if (matchPath(`${page.path}index.html`, trimmedPathname)) {
      foundPage = page
      pageCache[trimmedPathname] = page
      return true
    }

    return false
  })
github gatsbyjs / gatsby / packages / gatsby / cache-dir / find-page.js View on Github external
pages.some(page => {
    let pathToMatch = page.matchPath ? page.matchPath : page.path
    if (matchPath(pathToMatch, trimmedPathname)) {
      foundPage = page
      pageCache[trimmedPathname] = page
      return true
    }

    // Finally, try and match request with default document.
    if (matchPath(`${page.path}index.html`, trimmedPathname)) {
      foundPage = page
      pageCache[trimmedPathname] = page
      return true
    }

    return false
  })
github flow-typed / flow-typed / definitions / npm / @reach / router_v1.1.x / flow_v0.63.x-v0.103.x / test_router_v1.1.x.js View on Github external
it('works', () =&gt; {
      const history = createHistory(window);

      
        <div>Alright, we've established some location context</div>
      ;
    });