Linking pages in Hugo/markdown

Adeel picture Adeel · Oct 20, 2015 · Viewed 11.9k times · Source

I am new to HUGO (http://gohugo.io/) static site generator. I am running Hugo server locally accessible as localhost:1313. I am trying to link pages in two different sections. My "feature.md" file need a link to "grid_modules.md" and vice versa. Following is the directory structure for both files in hugo generated site.

~/mysite/content/about/feature.md

~/mysite/content/modules/grid_modules.md

What is the best way to link both pages together? What I am trying is the following

In feature.md:

"[grid_modules] (../modules/grid_modules)"

If I try to access this link, I get an error at "localhost:1313/about/modules/grid_modules" which I know is wrong location.

What I am missing in linking? Why I am not getting "localhost:1313/modules/grid_modules" instead.

Answer

Clay picture Clay · Oct 4, 2018

This answer builds upon the answer provided by bep. That answer is correct, but not very clear (as it took me many times reading it an trying different things before I found the solution).

As stated previously:

the URL of a page depends on your URL configuration (either through in https://gohugo.io/extras/permalinks/ or set directly as the URL on the individual page).

You can use the ref and relref tags within your markdown so that a link resolves to the correct URL.

For your example, this would look like one of the following (depending on whether you want an absolute or relative URL):

[grid_modules] ( {{< relref "modules/grid_modules" >}})
[grid_modules] ( {{< ref "modules/grid_modules" >}})