Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta duplicate #7166

Closed
krmao opened this issue Apr 26, 2019 · 1 comment
Closed

meta duplicate #7166

krmao opened this issue Apr 26, 2019 · 1 comment

Comments

@krmao
Copy link

krmao commented Apr 26, 2019

Bug report

meta duplicate

Describe the bug

meta duplicate
A clear and concise description of what the bug is.
if add in _document.js
just like

// _document is only rendered on the server side and not on the client side
// Event handlers like onClick can"t be added to this file

// ./pages/_document.js
import Document, {Html, Head, Main, NextScript} from "next/document";
import React from "react";

class MyDocument extends Document {
    static async getInitialProps(ctx) {
        const initialProps = await Document.getInitialProps(ctx);
        return {...initialProps};
    }

    render() {
        return (
            <Html>
            <Head>
                <link rel="icon" href="../static/favicon.ico" type="image/x-icon"/>
                <link rel="shortcut icon" href="../static/favicon.ico" type="image/x-icon"/>

                <meta name="viewport" content="width=device-width"/> // bug 在每个页面的 Head 里面加这一行,否则系统会默认加这一行
            </Head>
            <body>
            <Main/>
            <NextScript/>
            </body>
            </Html>
        );
    }
}

export default MyDocument;

and also add Head tag in page.js, just like

import React from "react";
import Head from "next/head";
import {withRouter} from "next/router";

export default withRouter(class extends React.Component {

    constructor(props) {
        super(props);
    }

    render() {
        console.log(this.props.router.asPath);
        return (
            <div>
                <Head>
                    <title>xxxxxx</title>
                </Head>
            </div>
        );
    }
});

the result is

nextjs will auto add to page

image

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of Next.js: [e.g. 6.0.2]

Additional context

Add any other context about the problem here.

@nblthree
Copy link
Contributor

Duplicate of #6919

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants