Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

router-hook

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

router-hook

```js // index.js import { RouterProvider } from "router-hook"

  • 5.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source
// index.js
import { RouterProvider } from "router-hook"


ReactDOM.render(
  <RouterProvider>
    <App />
  </RouterProvider>
  document.getElementById("root")
)

// routes.js
import { route } from "router-hook"

export const homeRoute = route("/")
export const registerRoute = route("/register")
export const loginRoute = route("/login")
export const accountRoute = route("/account")
export const editRoute = route("/thing/edit/:id?")
// Router.js
import { useLocation, useSetRoute, A } from "router-hook"
import {
  homeRoute,
  registerRoute,
  loginRoute,
  accountRoute,
  editRoute
} from "./routes"

function Router() {
  const location = useLocation()
  const setRoute = useSetRoute()
  const [user] = useUser()
  const path = location.pathname

  const auth = render => {
    if (user && user.id) {
      return render
    }
    return () => {
      setRoute(loginRoute.toUrl())
      return null
    }
  }

  return (
    <>
      <A className="App-link" href={loginRoute.toUrl()}>
        Login
      </A>
      {homeRoute.match(path, () => (
        <Home />
      ))}
      {registerRoute.match(path, () => (
        <Register />
      ))}
      {loginRoute.match(path, () => (
        <Login />
      ))}
      {accountRoute.match(
        path,
        auth(() => <Account />)
      )}
      {editRoute.match(
        path,
        auth(({ id }) => <Edit id={id} />)
      )}
    </>
  )
}

FAQs

Package last updated on 24 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc