DekGenius.com
JAVASCRIPT
how to go back to previous route in next.js
//if user not logged in
if (!auth.user) {
window.localStorage.setItem("path", router.asPath); //save current route
router.replace("/login"); //send user to login page
return <div> redirecting to login... </div>
}
//when user login
if (auth.user) {
const path = localStorage.getItem("path")
router.replace(path || "/"); //navigate to last route
return <div> Loading... </div>
);
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
How to go back to previous route after authentication in nextjs
componentDidMount() { // and/or componentDidUpdate, depending on what you're trying to do
if (!auth) {
Router.push({
pathname: '/login',
query: { from: {router.pathname} },
}))
}
}
//Then on the login page, after successful login:
handlePostLoginOk = () => {
const { router } = this.props;
if (router.query && router.query.from) {
router.push(router.query.from);
}
}
© 2022 Copyright:
DekGenius.com