小编jus*_*o19的帖子

getServerSideProps() 没有被调用 nextJS 13

试图熟悉nextJS 13。我遇到的是getServerSideProps函数没有预渲染页面道具。这是我第一次尝试,所以我不知道我是否做错了。

这是编写的代码/app/login/page.js

import Content from "@/components/content";
import LoginForm from "@/components/loginForm";
import Title from "@/components/title";

function Login({ message }) {
    return (
        <Content>
            <div className="ml-2 my-2">
                {message || "NextJS is ok."}
                <Title text="Login" />
            </div>
            <LoginForm />
        </Content>
    );
}

export default Login;

export async function getServerSideProps() {
    console.log("running getServerSideProps function..");
    return {
        props: { message: "NextJS is awesome!" },
    };
}
Run Code Online (Sandbox Code Playgroud)

我在这里想要实现的关键是在显示登录页面之前使用 axios 请求检查服务器的会话密钥。如果用户已登录,则应将用户重定向到主页。如果我能够使这个函数工作,这是未来的代码:

export async function getServerSideProps() {
    console.log("Im running getServerSideProps funct ");
    let isLoggedIn …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs axios next.js

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

axios ×1

javascript ×1

next.js ×1

reactjs ×1