Hugo panic when using {{.Next}}

Get following error if I include {{.Next}} or {{.Prev}} in _default/single.html.

_default/single.html:
{{ partial “header.html” . }}

<main class="content" role="main">
  <article class="article">

    {{ if not (isset .Params "content-only") }}
    <h1 class="article__title">{{ .Title }}</h1>

    {{ partial "article-meta.html" . }}

    <hr class="article__seperator">
    {{ end }}

    <div class="article__content">
      {{ .Content }}
    </div>
  </article>

</main>

<div class="navigation">
  <a href="{{.Prev.Permalink}}" target="_blank">Previous</a>
  <a href="{{.Next.Permalink}}" target="_blank">Next</a>
</div>

{{ partial "footer.html" . }}

Build Error:

Building sites … ERROR 2018/07/13 22:29:59 Failed to render "_default/single.html": runtime error: invalid memory address or nil pointer dereference
ERROR 2018/07/13 22:29:59 Stack Trace:
goroutine 29 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0x4c84f07, 0x17)
        /private/tmp/hugo-20180713-68487-o4xbkl/hugo-0.44/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x76
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc4207938a0, 0xc4204b6300)
        /private/tmp/hugo-20180713-68487-o4xbkl/hugo-0.44/src/github.com/gohugoio/hugo/hugolib/site.go:1734 +0x135
panic(0x4b4c740, 0x53664f0)
        /usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:502 +0x229
text/template.errRecover(0xc420793790)
        /usr/local/Cellar/go/1.10.3/libexec/src/text/template/exec.go:137 +0x1d4
panic(0x4b4c740, 0x53664f0)
        /usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:502 +0x229
github.com/gohugoio/hugo/hugolib.(*Page).Permalink(0x0, 0x0, 0x0)
        /private/tmp/hugo-20180713-68487-o4xbkl/hugo-0.44/src/github.com/gohugoio/hugo/hugolib/page.go:1159 +0x5
reflect.Value.call(0x4c31d60, 0xc420d6ec88, 0xc693, 0x4c37879, 0x4, 0x53ab1c8, 0x0, 0x0, 0x4c2c660, 0x1, ...)
        /usr/local/Cellar/go/1.10.3/libexec/src/reflect/value.go:447 +0x969
reflect.Value.Call(0x4c31d60, 0xc420d6ec88, 0xc693, 0x53ab1c8, 0x0, 0x0, 0xc42074e638, 0x13, 0x31)
        /usr/local/Cellar/go/1.10.3/libexec/src/refl
ERROR 2018/07/13 22:29:59 Stack Trace:
goroutine 28 [running]:
github.com/gohugoio/hugo/hugolib.stackTrace(0x4b0, 0x4c84f07, 0x17)
        /private/tmp/hugo-20180713-68487-o4xbkl/hugo-0.44/src/github.com/gohugoio/hugo/hugolib/page.go:280 +0x76
github.com/gohugoio/hugo/hugolib.(*Site).renderForLayouts.func1(0xc420ddf8a0, 0xc4204b6300)
        /private/tmp/hugo-20180713-68487-o4xbkl/hugo-0.44/src/github.com/gohugoio/hugo/hugolib/site.go:1734 +0x135
panic(0x4b4c740, 0x53664f0)
        /usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:502 +0x229
text/template.errRecover(0xc420ddf790)
        /usr/local/Cellar/go/1.10.3/libexec/src/text/template/exec.go:137 +0x1d4
panic(0x4b4c740, 0x53664f0)
        /usr/local/Cellar/go/1.10.3/libexec/src/runtime/panic.go:502 +0x229
github.com/gohugoio/hugo/hugolib.(*Page).Permalink(0x0, 0x0, 0x0)
        /private/tmp/hugo-20180713-68487-o4xbkl/hugo-0.44/src/github.com/gohugoio/hugo/hugolib/page.go:1159 +0x5
reflect.Value.call(0x4c31d60, 0xc42049a790, 0xc693, 0x4c37879, 0x4, 0x53ab1c8, 0x0, 0x0, 0x4c2c660, 0x1, ...)
        /usr/local/Cellar/go/1.10.3/libexec/src/reflect/value.go:447 +0x969
reflect.Value.Call(0x4c31d60, 0xc42049a790, 0xc693, 0x53ab1c8, 0x0, 0x0, 0xc420cbe928, 0x13, 0x31)
        /usr/local/Cellar/go/1.10.3/libexec/src/refl
Total in 200 ms
Error: Error building site: logged 3 error(s)

Probably because not all posts would have a .Next, eg if it is the last post. So .Next in this case would be <nil>, and accessing the .Permalink of <nil> crashes out.

Check first if it exists:

{{ with .Next }}
    <a href="{{ .Permalink }}"...
{{ end }}

before using its .Permalink

Hey it worked!!! Thank you thank you!!!