Works correctly when router not started (href is generated)
Works with defaultRoute router option
Guarantees
Automatic router retrieval from context
Memoized rendering — only re-renders when active state or props change
11. Related Components
Component/Hook
Relationship
useRouter
Used for getting router
RouterProvider
Required provider
11.1. See Also: Directive Alternatives
For applying navigation to any element without using Link, framework-specific directives are available:
Solid: use:link directive
Vue: v-link directive
Svelte: createLinkAction factory
Angular: realLink directive on <a> elements, [realLinkActive] for active class on any element
These provide low-level navigation control for custom elements.
Angular note: Angular uses the realLink directive on <a> elements instead of a <Link> component. Inputs: routeName, routeParams, routeOptions, activeClassName, activeStrict, ignoreQueryParams. The directive also checks target="_blank" and skips client-side navigation for external links.
functionSectionNav(){return(<nav>{/* Active for /users, /users/list, /users/123 */}<LinkrouteName="users"activeStrict={false}>
All Users
</Link>{/* Active ONLY for /users */}<LinkrouteName="users"activeStrict={true}>
Users Index
</Link></nav>);}
With Event Handling
functionTrackedLink({ routeName, children }){return(<LinkrouteName={routeName}onClick={()=>{analytics.track("link_clicked",{route: routeName});}}>{children}</Link>);}
Tip: To handle navigation results (success/error), call router.navigate() directly instead of using Link. The navigate() method returns a Promise<State>.
Anti-patterns
// Don't use Link outside RouterProviderfunctionBad(){return<LinkrouteName="home">Home</Link>;// Error!}// Wrap in RouterProviderfunctionGood(){return(<RouterProviderrouter={router}><LinkrouteName="home">Home</Link></RouterProvider>);}
// Don't use for external URLsfunctionBad(){return<LinkrouteName="https://google.com">Google</Link>;}// Use regular <a> for external linksfunctionGood(){return(<ahref="https://google.com"target="_blank"rel="noopener">
Google
</a>);}
// Don't pass router — it's ignoredfunctionBad(){constmyRouter=useRouter();return(<Linkrouter={myRouter}routeName="home">
Home
</Link>);}// Link gets router automaticallyfunctionGood(){return<LinkrouteName="home">Home</Link>;}
// routeOptions supported directly on LinkfunctionReplaceNavigation(){return(<LinkrouteName="checkout"routeOptions={{replace: true}}>
Checkout
</Link>);}
13. Migration from router5
Comparison of @real-router/react/Link with react-router5/Link from router5.
Version Comparison
router5 (react-router5)
Real Router (@real-router/react)
Implementation
withRouter(BaseLink) (HOC)
Function Component with useRouter()
Export
Named
Named
Router retrieval
routerContext.Consumer (render prop)
useRouter() hook
1. Breaking Changes
Severity
What Changed
Was
Now
Impact
LOW
Internal implementation
HOC withRouter(BaseLink)
FC with useRouter()
No API impact
LOW
successCallback
Prop on link
Removed
Use router.navigate() promise instead
LOW
errorCallback
Prop on link
Removed
Use router.navigate() promise instead
Props Changes
Props remain compatible:
Prop
Was
Now
Change
routeName
Yes
Yes
No change
routeParams
Yes
Yes
No change
routeOptions
Yes
Yes
No change
className
Yes
Yes
No change
activeClassName
Yes
Yes
No change
activeStrict
Yes
Yes
No change
ignoreQueryParams
Yes
Yes
No change
onClick
Yes
Yes
No change
successCallback
Yes
No
Removed
errorCallback
Yes
No
Removed
Examples
// routeOptions works directly on Link (no change needed from router5)<LinkrouteName="checkout"routeOptions={{replace: true}}>
Checkout
</Link>
2. Implementation Changes
Architecture
Was: HOC pattern — withRouter(BaseLink) creates component that gets router via routerContext.Consumer
Now: Hook pattern — Link uses useRouter() and passes to BaseLink
Advantages of New Approach
Simpler code: No intermediate HOC layer
Better typing: TypeScript works better with hooks than HOC
Fewer nesting levels: Simpler structure in DevTools
Modern React: Uses hooks instead of render props/HOC
Removed Components
withRouter HOC: No longer needed — use useRouter() hook directly
ConnectedLink: Was withRoute(BaseLink) — use Link + useRoute() instead
BaseLink: Merged into Link — all props including routeOptions are supported directly
3. Dependency Changes
Dependency
Was
Now
Router package
router5
@real-router/core
React bindings
react-router5
@real-router/react
Pattern
HOC (withRouter)
Hook (useRouter)
4. Migration Guide
Checklist
Update package import from react-router5 to @real-router/react
routeOptions works on Link directly — no changes needed
If successCallback/errorCallback was used — use router.navigate() which returns Promise<State>
If withRouter HOC was used — replace with useRouter() hook
If ConnectedLink was used — replace with Link or custom component with useRoute()
If BaseLink was used — replace with Link inside RouterProvider
Step-by-Step Migration
Update imports: Replace react-router5 with @real-router/react
routeOptions: Works on Link directly — no migration needed
Replace callbacks: If successCallback/errorCallback was used — call router.navigate() directly and handle the returned Promise<State>
Replace HOC: withRouter → useRouter() hook
Remove ConnectedLink: Use Link or create custom component with useRoute()
Remove BaseLink: Use Link inside RouterProvider — all props supported directly
5. Summary
Category
Status
Breaking Changes
LOW (successCallback, errorCallback removed)
New props
None
Removed props
successCallback/errorCallback
Behavior changes
Navigation results via router.navigate() promise
Optimizations
Hooks instead of HOC
Maximum severity: LOW — successCallback/errorCallback removed in favor of router.navigate() returning Promise<State>. routeOptions is supported directly on Link.