react-link-interceptor
v0.1.2
Published
React hook to intercept all <a> tag clicks in your SPA — handle internal routing and external link modifications with ease.
Downloads
298
Maintainers
Readme
react-link-interceptor
React hook to intercept all <a> tag clicks in your SPA. Handle internal routing and external link modifications with ease.
Install
npm install react-link-interceptorUsage
import { useLinkInterceptor } from 'react-link-interceptor'
function App() {
useLinkInterceptor({
onInternalLink(ctx) {
ctx.preventDefault()
navigate(ctx.path) // react-router
},
onExternalLink(ctx) {
ctx.url.searchParams.set('utm_source', 'myapp')
},
})
return <div>...</div>
}Docs & Playground
https://babu-ch.github.io/link-interceptor/?fw=react
