Ad
Nextjs Send Data (title Of Page) To Component
I am trying to set custom title for each page in my next.js project.
Let's say this is my simple Layout
const MainLayout = props => {
return (
<Layout style={{ minHeight: "100vh" }}>
<Head>
<title>I AM TITLE</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta charSet="utf-8" />
</Head>
<Layout>
<Content>{props.children}</Content>
<FooterView />
</Layout>
</Layout>
);
};
export default withTranslation('common')(MainLayout)
And login page.
import MainLayout from "../../components/layout/Layout";
class NormalLoginForm extends React.Component {
render() {
const { getFieldDecorator } = this.props.form;
return (
<MainLayout>
// LOGIN FORM
</MainLayout>
);
}
}
const WrappedNormalLoginForm = Form.create({ name: "normal_login" })(
NormalLoginForm
);
export default WrappedNormalLoginForm;
I just can't find the way (i am still new into this) how to send title from login page to layout like a variable. Thank you for any help.
Ad
Answer
You are going to want to pass in the title as a prop.
<MainLayout title='Login Page'>
// LOGIN FORM
</MainLayout>
<title>{props.title}</title>
You can also pass in a title as a dynamic variable:
<MainLayout title={loginPageTitle}>
// LOGIN FORM
</MainLayout>
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad