Next-Redirects-Preact
Next-Redirects-Preact is a small Redirect utility component for Next.js that can give fallback links for different conditions and with a small package size
Features
- 💡 Rich api options
- 🔥 Small and Fast
- 🛠 Fully supports esm
How to install
#using yarn
yarn add Next-Redirects-Preact
#using npm
npm i Next-Redirects-Preact
How to use
There is one component that can be used, it can be used in more than one way
You can use all these props with <Redirects>
component
Prop | usage | type |
---|---|---|
href | The link you want to redirect to | String |
status | The boolean that decides to redirect or not | boolean |
fallBack | (optional) The Fallback link if the condition is false | String |
asPath | (optional) The path mask if you want to show a different url than the real one | string |
shallow | (optional) The shallow option in next router for more info | boolean |
query | (optional) This props gives you the ability to send data with the direct you can access it via router.query.state on the other page | String, Number, Boolean as an array or as a single value |
example :
<Redirects href="/main" status={auth.loggedin} />
If you have a switch or more than the status
if (user.loggedin) {
<Redirects href="/Dashboard" />;
}
switch (condistionX) {
case admin:
<Redirects href="/Dashboard" />;
break;
case anonymous:
<Redirects href="/Login" />;
break;
default:
<Redirects href="/main" />;
}
This is just an example you can use it for whatever use cases you can imagine 🛠