Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
atomic-router
Advanced tools
Simple routing implementation that provides abstraction layer instead of inline URL's and does not break your architecture
Simple routing implementation that provides abstraction layer instead of inline URL's and does not break your architecture
history
instance and it works everywhere)$ npm install effector atomic-router
Create your routes wherever you want:
// pages/home
export const homeRoute = createRoute()
// pages/posts
export const postsRoute = createRoute<{ postId: string }>()
And then create a router
// app/routing
import { homeRoute } from '@/pages/home'
import { postsRoute } from '@/pages/home'
const routes = [
{ path: '/', route: homeRoute },
{ path: '/posts', route: postsRoute },
]
const router = createHistoryRouter({
routes: routes
})
// Attach history
const history = isSsr ? createMemoryHistory() : createBrowserHistory();
router.setHistory(history)
There are 3 purposes for using atomic routes:
export const getPostFx = createEffect<{ postId:string }, Post>(({ postId }) => {
return api.get(`/posts/${postId}`)
})
export const $post = restore(getPostFx.doneData, null)
postPage.$params
change://route.ts
import { getPostFx } from './model'
const postPage = createRoute<{ postId: string }>()
guard({
source: postPage.$params,
filter: postPage.$isOpened,
target: getPostFx
})
Imagine that we have a good architecture, where our code can be presented as a dependency tree.
So, we don't make neither circular imports, nor they go backwards.
For example, we have Card -> PostCard -> PostsList -> PostsPage
flow, where PostsList
doesn't know about PostsPage
, PostCard
doesn't know about PostsList
etc.
But now we need our PostCard
to open PostsPage
route.
And usually, we add extra responisbility by letting it know what the route is
const PostCard = ({ id }) => {
const post = usePost(id)
return (
<Card>
<Card.Title>{post.title}</Card.Title>
<Card.Description>{post.title}</Card.Description>
{/* NOOOO! */}
<Link to={postsPageRoute} params={{ postId: id }}>Read More</Link>
</Card>
)
}
With atomic-router
, you can create a "personal" route for this card:
const readMoreRoute = createRoute<{{ postId: id }}>()
And then you can just give it the same path as your PostsPage
has:
const routes = [
{ path: '/posts/:postId', route: readMoreRoute },
{ path: '/posts/:postId', route: postsPageRoute },
]
Both will work perfectly fine as they are completely independent
// Stores
route.$isOpened // Store<boolean>
route.$params // Store<{ [key]: string }>
route.$query // Store<{ [key]: string }>
// Events (only watch 'em)
route.opened // Event<{ params: RouteParams, query: RouteQuery }>
route.left // Event<{ params: RouteParams, query: RouteQuery }>
// Effects
route.open // Effect<RouteParams>
route.navigate // Effect<{ params: RouteParams, query: RouteQuery }>
FAQs
Simple routing implementation that provides abstraction layer instead of inline URL's and does not break your architecture
The npm package atomic-router receives a total of 813 weekly downloads. As such, atomic-router popularity was classified as not popular.
We found that atomic-router demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
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.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.