Effector Next Redirect
Redirect to any URL in NextJS both on the client and on the server depending on the state of the store
Installation
npm install effector-next-redirect
or yarn
yarn add effector-next-redirect
Example
-
Redirect to the
/login
page, depending on the state of the$isAccessDenied
store// pages/index.jsximport React from "react";import withRedirect from "effector-next-redirect";import createStore from "effector";const $isAccessDenied = ;// redirect with setting 302 status codeconst enhance = ;{return<div><h1>HomePage</h1></div>;}HomePage; -
Redirect to the
/login
page using replace on the client// pages/index.jsximport React from "react";import withRedirect from "effector-next-redirect";import createStore from "effector";const $isAccessDenied = ;// redirect with setting 301 status codeconst enhance = ;{return<div><h1>HomePage</h1></div>;}HomePage;
Configuration
The withRedirect
function expects to receive the settings object as the third argument:
asUrl
(string, optional) : maskurl
for the browsercode
(number, optional) : status code set by the server after redirectionreplace
(boolean, optional) : useRouter.replace
instead ofRouter.push
in browser