在Rootlayout、console.log(props)
export default function RootLayout(props) {
console.log("props in layout",props)
return (
<div>
{props.children}
</div>
);}
这就是你会看到的
props in layout {
children: {
'$$typeof': Symbol(react.element),
type: {
'$$typeof': Symbol(react.module.reference),
filepath: '/home/tesla/Documents/projects/next.js/youtube-next13-static-blog/node_modules/next/dist/client/components/layout-router.js',
name: '',
async: false
},
key: null,
ref: null,
props: {
parallelRouterKey: 'children',
segmentPath: [Array],
error: undefined,
errorStyles: undefined,
loading: undefined,
loadingStyles: undefined,
hasLoading: false,
template: [Object],
templateStyles: undefined,
notFound: [Object],
notFoundStyles: undefined,
childProp: [Object],
rootLayoutIncluded: true
},
_owner: null,
_store: {}
},
// THIS IS HOW WE PASS PROPS
params: {}
}
许多属性不可扩展,但params。我们可以动态地向这个对象添加属性。例如
props.params.newProp = "testing";
现在访问page.js和
const Page = (props) => {
console.log("props in page", props);
return ()}
你会看到道具被添加到params对象