Socket
Socket
Sign inDemoInstall

@atomic-router/react

Package Overview
Dependencies
12
Maintainers
3
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @atomic-router/react

React bindings for [atomic-router](https://github.com/kelin2025/atomic-router)


Version published
Weekly downloads
0
decreased by-100%
Maintainers
3
Created
Weekly downloads
 

Readme

Source

Atomic-router-react

React bindings for atomic-router

Example on StackBlitz

Installation

Install core and react bindings:

npm i atomic-router atomic-router-react

Don't forget about peer dependencies, if you haven't installed them yet:

npm i effector effector-react react

Usage

RouterProvider - provides router instance

Wrap your app into this:

import { createHistoryRouter } from 'atomic-router'
import { RouterProvider, Route } from 'atomic-router-react'

import { HomePage } from './routes'

const router = createHistoryRouter({ routes });

const App = () => {
  return (
    <RouterProvider router={router}>
      <Route route={homeRoute} view={HomePage} />
    </RouterProvider>
  );
};

Simple usage:

import { createRoute } from 'atomic-router'
import { Link } from 'atomic-router-react'

const homeRoute = createRoute<{postId:string}>()
const postRoute = createRoute<{postId:string}>()

<Link to={homeRoute}>Route link</Link>
<Link to={postRoute} params={{ postId:1 }}>Route link with params</Link>
<Link to="https://example.com">External link</Link>

All params:

import { Link } from 'atomic-router-react'

<Link
  to={route}
  params={{ foo: 'bar' }}
  query={{ bar: 'baz' }}
  activeClassName="font-semibold text-red-400"
  inactiveClassName="opacity-80"
/>

Route - render route

import { Route } from 'atomic-router-react'

<Route route={homeRoute} view={HomePage} />
import { useLink } from 'atomic-router-react'
import { createRoute } from 'atomic-router'

// example path: /some/route/:someId
const someRoute = createRoute<{ someId: number }>()

function SomeComponent() {
  const path = useLink(someRoute, { someId: 1 })
  // -> /some/route/1
}

Be sure, route is passed into routes for createHistoryRoutes. Else hook will throw [useLink] Route not found.

FAQs

Last updated on 05 Aug 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc