
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
react-router-v18
Advanced tools
React Router v18 is a fork of React Router 3.2.4 upgraded to support React 16.3+, 17, 18, and 19.
React Router is a complete routing library for React. It keeps your UI in sync with the URL with a simple API and powerful features like lazy code loading, dynamic route matching, and location transition handling built right in.
React.createContext() instead of legacy contextcomponentWillMount and componentWillReceivePropsView live examples on GitHub Pages:
Examples include:
This version supports:
React.createContext())Note: React 0.14, 15, and 16.0-16.2 are not supported due to the use of
React.createContext()which was introduced in React 16.3.
If you're upgrading from the original React Router 3.2.4, see the UPGRADE_TO_REACT_18.md for detailed migration guide. The API remains compatible, but internal implementation has been updated for React 18/19.
We support all browsers and environments where React runs.
Using npm:
npm install --save react-router-v18
Or using yarn:
yarn add react-router-v18
Then with a module bundler like webpack that supports either CommonJS or ES2015 modules:
// using an ES6 transpiler, like babel
import { Router, Route, Link, browserHistory } from 'react-router-v18'
// not using an ES6 transpiler
var Router = require('react-router-v18').Router
var Route = require('react-router-v18').Route
var Link = require('react-router-v18').Link
var browserHistory = require('react-router-v18').browserHistory
import React, { useState, useEffect } from 'react'
import { createRoot } from 'react-dom/client'
import { Router, Route, Link, browserHistory } from 'react-router-v18'
// Function component with hooks
const App = ({ children }) => (
<div>
<h1>App</h1>
<nav>
<Link to="/about">About</Link>
<Link to="/users">Users</Link>
</nav>
{children}
</div>
)
const About = () => (
<div>
<h2>About</h2>
<p>This is the about page.</p>
</div>
)
const Users = ({ children }) => {
const [users, setUsers] = useState([])
useEffect(() => {
// Fetch users data
fetchUsers().then(setUsers)
}, [])
return (
<div>
<h2>Users</h2>
<ul>
{users.map(user => (
<li key={user.id}>
<Link to={`/user/${user.id}`}>{user.name}</Link>
</li>
))}
</ul>
{children}
</div>
)
}
const User = ({ params }) => {
const [user, setUser] = useState(null)
useEffect(() => {
// Route components receive params as props
findUserById(params.userId).then(setUser)
}, [params.userId])
if (!user) return <div>Loading...</div>
return (
<div>
<h3>{user.name}</h3>
<p>Email: {user.email}</p>
</div>
)
}
// React 18 rendering with createRoot
const container = document.getElementById('root')
const root = createRoot(container)
root.render(
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="about" component={About}/>
<Route path="users" component={Users}>
<Route path="/user/:userId" component={User}/>
</Route>
</Route>
</Router>
)
If you prefer the class-based API, you can still use create-react-class:
import React from 'react'
import createReactClass from 'create-react-class'
import { createRoot } from 'react-dom/client'
import { Router, Route, Link, browserHistory } from 'react-router-v18'
const App = createReactClass({
render() {
return (
<div>
<h1>App</h1>
<nav>
<Link to="/about">About</Link>
<Link to="/users">Users</Link>
</nav>
{this.props.children}
</div>
)
}
})
// ... rest of components
// React 18 rendering with createRoot
const container = document.getElementById('root')
const root = createRoot(container)
root.render(
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="about" component={About}/>
</Route>
</Router>
)
Note:
- For React 18+, use
createRootfromreact-dom/clientinstead ofReactDOM.render- Function components with hooks are recommended for new code
createReactClassis still supported for backward compatibility- See UPGRADE_TO_REACT_18.md for complete migration details
See more examples in the Examples directory.
This project is a fork of React Router 3.2.4 with upgrades for React 18/19 compatibility. The core API remains the same, making it a drop-in replacement for projects using React Router 3.2.4 with React 16.3+.
React.createContext()componentWillMount, componentWillReceiveProps)createRoot instead of ReactDOM.render)react-transition-group v4+ APISee UPGRADE_TO_REACT_18.md for complete details.
MIT - Same as the original React Router 3.2.4
免责声明 / Disclaimer
This is a community-maintained fork of React Router 3.2.4. The original authors and maintainers of React Router are not responsible for this fork or any issues that may arise from using it.
Use at your own risk. The maintainers of this fork are not liable for any damages, data loss, or issues that may occur from using this software.
If you use this code, you acknowledge that:
这是一个社区维护的 React Router 3.2.4 分支版本。React Router 的原始作者和维护者不对此分支或使用它可能出现的任何问题负责。
使用风险自负。 此分支的维护者不对使用本软件可能造成的任何损害、数据丢失或问题承担责任。
如果您使用此代码,即表示您承认:
FAQs
A complete routing library for React
The npm package react-router-v18 receives a total of 4 weekly downloads. As such, react-router-v18 popularity was classified as not popular.
We found that react-router-v18 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
/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.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.