第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Nextjs - 將道具從自定義 _app.js 傳遞到 <Navbar> 組件?

Nextjs - 將道具從自定義 _app.js 傳遞到 <Navbar> 組件?

如何將道具從這里傳遞到要添加到 Head 組件下的導(dǎo)航欄組件?我已經(jīng)使用 getServerSideProps 在 index.js 頁(yè)面中完成了此操作,但它似乎在 _app.js 文件中不起作用。import "../_app.css";import React from "react";import PropTypes from "prop-types";import Head from "next/head";import { ThemeProvider } from "@material-ui/core/styles";import CssBaseline from "@material-ui/core/CssBaseline";import theme from "../theme";export default function MyApp({ Component, pageProps }) {    React.useEffect(() => {        // Remove the server-side injected CSS.        const jssStyles = document.querySelector("#jss-server-side");        if (jssStyles) {            jssStyles.parentElement.removeChild(jssStyles);        }    }, []);    return (        <React.Fragment>            <Head>                <title>Furnibnz | Baldai Internetu ir Nemokamas Pristatymas</title>                <meta                    name="viewport"                    content="minimum-scale=1, initial-scale=1, width=device-width"                />            </Head>            <ThemeProvider theme={theme}>                {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}                <CssBaseline />                <Component {...pageProps} />            </ThemeProvider>        </React.Fragment>    );}MyApp.propTypes = {    Component: PropTypes.elementType.isRequired,    pageProps: PropTypes.object.isRequired,};有沒有更好的方法在每個(gè)頁(yè)面中使用導(dǎo)航欄組件,或者這是正確的方法嗎?
查看完整描述

1 回答

?
炎炎設(shè)計(jì)

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊

當(dāng)這是我最大的問題時(shí)的美好時(shí)光哈哈

對(duì)于真正需要答案的人:

您當(dāng)前無法在 _app 組件中使用 getStaticProps 和 getServerSideProps ,因此,如果我沒記錯(cuò)的話,我會(huì)嘗試獲取初始數(shù)據(jù)(可能是類別列表)并將其傳遞給組件。要在 _app 級(jí)別獲取初始數(shù)據(jù),您應(yīng)該使用 getInitialProps(NextJs 開發(fā)人員建議避免使用它),但請(qǐng)注意,使用它會(huì)阻止 NextJs 自動(dòng)靜態(tài)優(yōu)化不依賴于任何類型獲取方法的頁(yè)面(它們將在服務(wù)器端呈現(xiàn) - 即使是一個(gè)簡(jiǎn)單的“關(guān)于我們”頁(yè)面,也可以作為靜態(tài) html 提供)

查看完整回答
反對(duì) 回復(fù) 2023-10-14
  • 1 回答
  • 0 關(guān)注
  • 157 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)