L
L
lucky42020-10-06 15:13:27
React
lucky4, 2020-10-06 15:13:27

How to make a master page in nextjs?

I am rebuilding the application from cra to nextjs framework.

And now the problem I'm facing is the transition of react-route-dom to nextjs.
For example, there is app.js in cra where, for example, header + main-page + footer is located.
Header and footer, the same on all pages. But the main page should change.

How is this implemented in nextjs? Perhaps you need to somehow make a master page (for example, like in nodejs with engine templates or like in .net razor)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-10-06
@lucky4

next has _app.js , in which all pages will be wrapped, here you can put common elements in this file, for example

// /pages/_app_.js
import React from 'react'
import App from 'next/app'
import SiteLayout from './components/SiteLayout'

class MyApp extends App {
  render() {
    const { Component, pageProps } = this.props
    return (
      <SiteLayout>
        <Component {...pageProps}></Component>
      </SiteLayout>
    )
  }
}

export default MyApp

https://adamwathan.me/2019/10/17/persistent-layout...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question