Redirect 如果用户未使用next.js登录,如何限制对about页面的访问

Redirect 如果用户未使用next.js登录,如何限制对about页面的访问,redirect,next.js,Redirect,Next.js,如果用户未使用next.js登录,如何限制对about页面的访问 我需要使用node.js限制对about页面和项目中其他一些页面的访问 node.js不支持react中的重定向功能,因此请指定任何替代方法我认为您应该在客户端代码而不是服务器上处理该问题。例如: import Router from 'next/router' class PrivatePage extends React.Component { static async getInitialProps () {

如果用户未使用next.js登录,如何限制对about页面的访问

我需要使用node.js限制对about页面和项目中其他一些页面的访问


node.js不支持react中的重定向功能,因此请指定任何替代方法

我认为您应该在客户端代码而不是服务器上处理该问题。例如:

import Router from 'next/router'

class PrivatePage extends React.Component {
  static async getInitialProps () {
    const loggedIn = getAuthData();
    // getAuthData is some method that returns you if user is logged in. You  
    // could take it from cookies/localStorage/redux store or fetch them.
    if (!loggedIn) {         
       Router.push('/login')
    }
  }
}

我认为应该在客户端代码上处理,而不是在服务器上。例如:

import Router from 'next/router'

class PrivatePage extends React.Component {
  static async getInitialProps () {
    const loggedIn = getAuthData();
    // getAuthData is some method that returns you if user is logged in. You  
    // could take it from cookies/localStorage/redux store or fetch them.
    if (!loggedIn) {         
       Router.push('/login')
    }
  }
}