question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nextjs is link not working in single line

See original GitHub issue
import Link from 'next/link';

const Index =  () => {
    return (
        <div>
            <ul>
                <li>
                    <Link href="/">  <a>Home</a>  </Link>
                </li>
            </ul>
            <h1>Hellow Next.js</h1>
        </div>
    )
}
export default Index;

First i declared <a> </a> tag in one line into <Link></Link> but its through me Error

React.Children.only expected to receive a single React element child.

After i added a line break like this

<Link href="/">  
     <a>Home</a>  
</Link>

it works fine. whats the problem?

Thanks 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Jul 19, 2019

I don’t think we can make changes here, also the issue doesn’t follow / ignores the issue template.

1reaction
kachkaevcommented, Jul 19, 2019

Yes, the space is the thing to blame here. It’s not to do with Next.js and is related to how jsx (React markup) is transpiled to normal JS. https://stackoverflow.com/a/32690647

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nextjs is link not working in single line · Issue #8035 - GitHub
Yes, the space is the thing to blame here. It's not to do with Next.js and is related to how jsx (React markup)...
Read more >
<Link> does not work as expected in NextJS - Stack Overflow
I tried adding an <a> tag under my Link and it worked. I am coming from react-router, and felt that just adding the...
Read more >
next/link | Next.js
Enable client-side transitions between routes with the built-in Link component.
Read more >
Link Component - Navigate Between Pages | Learn Next.js
In Next.js, you can use the Link Component next/link to link between pages in your application. <Link> allows you to do client-side navigation...
Read more >
no-html-link-for-pages - Next.js
The Link component is required in order to enable client-side route transitions between pages and provide a single-page app experience.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found