Menu pageRef doesn't work for pageRefs shorter than 4 characters

My menu:

menu:
  main:
    - name: Go
      pageRef: /go
      weight: 10

My loop:

{{- range site.Menus.main}}
    <a href="{{ .URL }}">{{ .Name }}</a>
{{- end}}

The output is not /go but just /, even though Hugo does generate the /go list page correctly. When I change /go to some name with 4 or more characters, it seems to work.

Any ideas?

We’d need to see your project to understand the problem.

Menu pageRef values do not have a minimum length requirement. Here’s an example:

git clone --single-branch -b hugo-forum-topic-45759 https://github.com/jmooring/hugo-testing hugo-forum-topic-45759
cd hugo-forum-topic-45759
hugo server

Ok, so after debugging this for a while, I’ve found the issue: I had an article where two taxonomies were assigned the same term:

categories:
- Go
technologies:
- Go

This seems to cause a collision and the respective page URL won’t be rendered at all. I’m not sure why, though, because I would expect them to be rendered under different URLs.

So, again…

I’ve created a minimal working example here: GitHub - dominikbraun/issue-45759

The href of the link should be /go, but it is empty. If you remove the technology taxonomy from content/article/article1.md, it will work.

The pageRef property is the path to a content file; it is not a URL. Hugo creates taxonomy and term pages even if you haven’t created a corresponding content file. The corresponding content file for the “go” category is content/categories/go/_index.md. So your menu should be:

menu:
  main:
    - name: Go
      pageRef: /categories/go
      weight: 10

https://gohugo.io/content-management/menus/#properties-site-configuration

Thanks, now I get how it works!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.