
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
react-router-min
Advanced tools
Only 5k. A lightweight react router component and hooks for ReactJS. Support dyamic routes, multiple routes, base path, presetQuery. useRouter and Link component Provided.
Only 5k. A lightweight react router component and hooks for ReactJS.
npm install react-router-min
// App.js
import { createRouter } from 'react-router-min'
const { Main } = createRouter({
routes: [{ path: '/', Component: Home }],
config: { type: 'history', cleanUrl: true, stripIndex: false },
})
function App() {
return <Main />
}
<script src="https://unpkg.com/react-router-min/lib/index.umd.js"></script>
Follow tutorial to learn how to use react-router-min
git clone https://github.com/billypc025/react-router-min.git
cd react-router-min && npm install
npm run demo

react-router-min supports multiple router instances. Use createRouter to create a router instance, and each instance works independently.
import { createRouter } from 'react-router-min'
// create Router instance
const {
Link, // create a Link component
Main, // create Router Main component
Router, // create Router component
useRouter, // create a useRouter Hooks (Can obtain the parsed `path` and `query`)
pushUrl, // push state url for function call
replaceUrl, // replace state url for function call
routerList, // generate a path list based on routes
} = createRouter({ routes, config })
routes can be Array of Record, routes is not required.
// Array type, with children
createRouter({
routes: [
{
path: '/',
Component: Root,
children: [
{ index: true, Component: Home },
{ path: 'about', Component: About },
{
path: 'auth',
Component: AuthLayout,
children: [
{ path: 'login', Component: Login },
{ path: 'register', Component: Register },
],
},
{
path: 'concerts',
children: [
{ index: true, Component: ConcertsHome },
{ path: ':city', Component: ConcertsCity },
{ path: 'trending', Component: ConcertsTrending },
],
},
],
},
],
})
// Flattened Array
createRouter({
routes: [
{ path: '/', Component: Home },
{ path: '/about', Component: About },
{ path: '/auth', Component: AuthLayout },
{ path: '/auth/login', Component: Login },
{ path: '/auth/register', Component: Register },
{ path: '/concerts/', Component: ConcertsHome },
{ path: '/concerts/city', Component: ConcertsCity },
{ path: '/concerts/trending', Component: ConcertsTrending },
],
})
// Record type
createRouter({
routes: {
'/': Home,
'/about': About,
'/auth': AuthLayout,
'/auth/login': Login,
'/auth/register': Register,
'/concerts/': ConcertsHome,
'/concerts/city': ConcertsCity,
'/concerts/trending': ConcertsTrending,
},
})
dynamic routes
VariableName// URL: https://domain.com/foo/1/article?id=xxxxx
//-- routes --
const routes = { '/foo/[category]/article': ArticleComponent }
//-- ArticleComponent.js --
function ArticleComponent({ category }) {
console.log(category)
//=> '1'
return '...'
}
SegmentName// URL: https://domain.com/foo/1/2/article?id=xxxxx
//-- routes --
const routes = { '/foo/[...tags]/article': ArticleComponent }
//-- ArticleComponent.js --
function ArticleComponent({ tags }) {
console.log(tags)
//=> ['1', '2']
return '...'
}
const { Main } = createRouter({
config: { base: '', type: 'history', cleanUrl: true, stripIndex: true },
})
config.base router base pathname. Defaults to '', useful for Micro-FE.
config.presetQuery preset query record, forever existing, can be covered.
config.type The type of routing to use, either 'history' or 'hash'. Defaults to 'history'
config.cleanUrl Whether to clean the URL by removing extension name. Defaults to true.
config.stripIndex Whether to strip "index" from the URL path. Defaults to true.
The page component must be wrapped by the Main component.
const { Main } = createRouter({ routes })
function App() {
return (
<Main>
<Layout />
</Main>
)
}
Link component return <a/>, but prevented default event to make SPA. Usage is same as <a/>.
There are two ways to import.
import from instance return by creatRouter (recommend)
//-- AppRouter.js --
import { createRouter } from 'react-router-min'
const { Main, Link } = createRouter()
export { Link, Main as default }
//-- PageComponent.js --
import { Link } from './AppRouter.js'
function PageComponent() {
return (
<>
<Link href='/foo'>foo</Link>
{/* replace state link */}
<Link href='/foo' type="replace">foo</Link>
{/* with query */}
<Link href='/foo?n=1'>foo</Link>
<Link href='/foo' query={{ a:1 }}>foo</Link>
</>
)
}
import directly from 'react-router-min'
import { Link } from 'react-router-min'
function PageComponent() {
return (
<>
<Link href='/foo'>foo</Link>
{/* replace state link */}
<Link href='/foo' type="replace">foo</Link>
{/* with query */}
<Link href='/foo?n=1'>foo</Link>
<Link href='/foo' query={{ a:1 }}>foo</Link>
{/* need to manually pass base */}
<Link href='/foo' options={{ base: '/base' }}>foo</Link>
{/* need to manually pass router type */}
<Link href='/foo' options={{ type: 'hash' }}>foo</Link>
</>
)
}
path and query// URL: https://domain.com/foo?a=1
function PageComponent() {
const { path, query } = useRouter()
console.log({ path, query })
// => { path: '/foo', query: { a: 1 } }
return '...'
}
// URL: https://domain.com/#/foo?a=1
function PageComponent() {
const { path, query } = useRouter()
console.log({ path, query })
// => { path: '/foo', query: { a: 1 } }
return '...'
}
// URL: https://domain.com/base/foo?a=1
//-- router.js --
const { Main } = createRouter({ routes, config: { base: '/base' } })
//-- PageComponent.js --
function PageComponent() {
const { path, query } = useRouter()
console.log({ path, query })
// => { path: '/foo', query: { a: 1 } }
return '...'
}
Function to push or replace a new URL to the history stack. There are two ways to import.
import from instance return by creatRouter (recommend)
imported in this way will automatically apply the config preset by creatRouter
//-- AppRouter.js --
import { createRouter } from 'react-router-min'
const { Main, pushUrl } = createRouter({
routes: [
{ path: '/', Component: Home },
{ path: '/foo', name: 'foo', Component: PageComponent },
],
})
export { pushUrl, Main as default }
//-- function call in PageComponent --
import { pushUrl } from './AppRouter.js'
pushUrl('/foo')
pushUrl('/foo?a=1')
pushUrl('/foo?a=1', { query: { b: 2 } })
pushUrl({ path: '/foo', query: { a: 1 } })
pushUrl({ name: 'foo', query: { a: 1 } }) // by name
usage of replaceURL is the same as pushURL.
import directly from 'react-router-min'
imported in this way, need to manually pass some configurations.
import { pushUrl } from 'react-router-min'
pushUrl('/foo')
pushUrl('/foo?a=1')
pushUrl('/foo?a=1', { query: { b: 2 } })
pushUrl({ path: '/foo', query: { a: 1 } })
pushUrl({ name: 'foo', query: { a: 1 } }) // by name
// need to manually pass base
pushUrl('/foo', { base: '/base' })
// need to manually pass router type
pushUrl('/foo', { type: 'hash' })
FAQs
Only 5k. A lightweight react router component and hooks for ReactJS. Support dyamic routes, multiple routes, base path, presetQuery. useRouter and Link component Provided.
We found that react-router-min demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.