Gathering detailed insights and metrics for nextjs-redirect
Gathering detailed insights and metrics for nextjs-redirect
Gathering detailed insights and metrics for nextjs-redirect
Gathering detailed insights and metrics for nextjs-redirect
npm install nextjs-redirect
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
148 Stars
130 Commits
10 Forks
2 Watching
2 Branches
2 Contributors
Updated on 31 May 2024
JavaScript (53.13%)
TypeScript (38.26%)
HTML (8.61%)
Cumulative downloads
Total Downloads
Last day
4.5%
2,364
Compared to previous day
Last week
12.6%
11,146
Compared to previous week
Last month
0.3%
35,929
Compared to previous month
Last year
9.6%
310,552
Compared to previous year
Redirect to any URL in NextJS both in client and server
1npm install nextjs-redirect
Let's say you want to create a page /donate
that redirects the user to paypal.me with a default value for the money. You create the page as you always do in NextJS (pages/donate.js
) and then just use this component with the URL you want:
1// pages/donate.js 2import redirect from 'nextjs-redirect' 3export default redirect('https://paypal.me/pablopunk/5')
You can checkout this example live in pablopunk.com
By default, it will send a 301 status code. This can be customized by an optional parameter:
1redirect('https://google.es', { statusCode: 302 })
When redirecting on the client side, if the redirected page is dynamic (pages/user/[userId]/info.js
), the following redirect will trigger a page refresh:
1redirect('/user/42/info')
In this case you can use the asUrl
option to make a smooth transition between pages without any refresh:
1redirect('/user/[userId]/info', { asUrl: '/user/42/info' })
This package is compatible with next export
since version 4.0.0. See PR #4 for more details.
In case the navigation is happening client-side, you can use this package as a HOC to provide your custom components/styles for the UI:
1import redirect from 'nextjs-redirect' 2 3const Redirect = redirect('https://github.com/pablopunk') 4 5export default () => ( 6 <Redirect> 7 <MyLayout>Redirecting to github!</MyLayout> 8 </Redirect> 9)
Let's say you have a single page called /redirect
, and you wanna use it for all kinds of redirects:
/redirect?to=https://google.com
/redirect?next=https://twitter.com
/redirect?url=https://pablopunk.com
Pretty cool huh!? You can do this with nextjs-redirect
by passing the name of the parameter you want on the url. For the examples above:
1// NOTE: These are 3 separate examples, you can only choose one name per page 2redirect('to', {params: true}) 3redirect('next', {params: true}) 4redirect('url', {params: true})
Working with locales routes? Take a look at nextjs-redirect-locale.
There's now a native way of handling redirects on NextJS. You can read more about it here. It requires you to modify your next.config.js
. Personally I still think nextjs-redirect
is a more friendly way of doing it, and also more flexible. For example you can do dynamic redirects on the server, depeding on the request, which is useful when working with locales (checkout nextjs-redirect-locale) and other request-dependent redirects. It also allows you make client redirects with a custom layout.
MIT
Pablo Varela |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More