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.

Using href directly in Link

See original GitHub issue

Hi, I have a url that is part of the data. I tried using the href value directly instead of params and route but it seems to be doing a full page navigation. Is it expected?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
fridayscommented, Apr 15, 2017

When using only href, it’s not handled by next-routes but passed to the original Link component, which expects a corresponding file in the pages folder (therefore the 404). To use the route defined in routes.js, do it like this:

<Link route='detail' params={{id: 123}}><a>Detail</a></Link>

Alternatively next.js lets you decorate the displayed URL in any way, but you need to tell it which page to render and pass the params. That’s what next-routes normally does for you. You can do it manually like this:

<Link href='/detail?id=123' as='/this-can-be-anything'><a>Detail</a></Link>

Check out the docs here: https://github.com/zeit/next.js#with-link

Hope it helps!

1reaction
khankuancommented, Apr 15, 2017
// routes.js
const nextRoutes = require('next-routes')
const routes = module.exports = nextRoutes()

routes.add('index', '/')
routes.add('detail', '/detail/:id')

// pages/index.js
import { Link } from "../routes";
<div>
   <Link href="/detail/123"><a>Detail</a></Link>
</div>

Without add params and route to Link, it causes a full page reload. Also, the client displays a brief 404 before showing the new page again.

Cheers 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Link – How to Insert a Link to a Website with HREF Code
The href is an attribute used to reference another document. You can find it on link tags and anchor tags. The href attribute...
Read more >
HTML Links Hyperlinks - W3Schools
The most important attribute of the <a> element is the href attribute, which indicates the link's destination. The link text is the part...
Read more >
What Are a Href Links? HTML Links Explained - Semrush
The href attribute link (short for “Hypertext REFerence”) indicates the relationship between pages to search engines. href is an attribute of ...
Read more >
How to use a href in HTML for adding links to your website
a href is used to include external and internal links on a website. The authorized values for the HTML attribute href are clearly...
Read more >
HTML Anchors: Here's How To Create Links For Fast ...
An href can do a lot more than just link to another website. It can be used to link directly to any element...
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