
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
unplugin-react-routes
Advanced tools
File-based routing, similar to Next.js App Router. Powered by unplugin.
npm i -D unplugin-react-routes
# or
yarn add -D unplugin-react-routes
# or
pnpm add -D unplugin-react-routes
# or
bun add -D unplugin-react-routes
// vite.config.ts
import reactRoutes from 'unplugin-react-routes/vite'
export default defineConfig({
plugins: [
reactRoutes({
/* options */
}),
],
})
Add TypeScript type support.
// vite-env.d.ts
/// <reference types="vite/client" />
/// <reference types="unplugin-react-routes/client" />
If you don't have a .d.ts file, you can add this code to tsconfig.json.
// tsconfig.json
{
"compilerOptions": {
// ...
"types": ["unplugin-react-routes/client"]
}
}
Changes to the entry file
// main.tsx
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
-import App from './App.tsx'
+import { createBrowserRouter } from 'react-router'
+import { RouterProvider } from 'react-router/dom'
+import { routes } from 'virtual:react-routes'
import './index.css'
createRoot(document.getElementById('root')!).render(
<StrictMode>
- <App />
+ <RouterProvider router={createBrowserRouter(routes)} />
</StrictMode>,
)
Create an app folder under src, move App.tsx to app and rename it to index.tsx, taking care to adjust the relative path of the import statement.
Change export statement.
// index.tsx
// export default App
export const Component = () => {
/* Code for the `App` component. */
}
Start the development server, if it is already started, restart it.
You should now see what index.tsx presents in your browser.
You can also export these components:
// https://reactrouter.com/start/framework/route-module#errorboundary
export const ErrorBoundary = () => {
/* code */
}
The following routes have been implemented
Index routes render into their parent's at their parent's URL (like a default child route).
Usage: /src/app/_index/index.tsx
import { RouteObject } from 'react-router'
// The generated structure looks like this
export default [
{
path: '/',
children: [
{
index: true,
},
],
},
] satisfies RouteObject[]
Nesting based on directory paths.
Usage: /src/app/a/b/c/index.tsx
import { RouteObject } from 'react-router'
// The generated structure looks like this
export default [
{
path: '/',
children: [
{
path: 'a',
children: [
{
path: 'b',
children: [
{
path: 'c',
},
],
},
],
},
],
},
] satisfies RouteObject[]
Using a pair of [] wrappers, the internal name will be used as the name of the property fetched in useParams.
Usage: /src/app/[postId]/index.tsx
import { RouteObject } from 'react-router'
// The generated structure looks like this
export default [
{
path: '/',
children: [
{
path: ':postId',
},
],
},
] satisfies RouteObject[]
The following is the default values of the plugin.
reactRoutes({
// relative paths to the directory to search for pages.
dir: 'src/app',
// specify the file name as the routing page file.
index: 'index.tsx',
})
FAQs
File-based routing, similar to Next.js App Router.
We found that unplugin-react-routes demonstrated a not healthy version release cadence and project activity because the last version was released 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.