Nav: link to the site root with an anchor (/#section) gets is_parent on every page

未关闭
#16,066 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@duncanmcclean 已经在做这个了。

开始于 2026年11月26日。

  • #16067 来自 @duncanmcclean —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
laravel, php
领域
backend

调研方向

Read src/Tags/Structure.php around Structure::isParent() and the URL behavior in src/Facades/Endpoint/URL.php; UrlTest::ancestorProvider() is mentioned as covering fragment handling. Compare how the site-root check and ancestor check treat fragments, then add a regression test for /#contact and /de#contact. Done means these links no longer report is_parent on non-home pages; a pull request is already open.

由索引模型根据 Issue 内容生成。

描述

navigations
Bug description

A navigation item that links to the site root with an anchor, like /#contact (or /de#contact on a multisite where the site URL is /de), gets is_parent: true on every page except the home page itself. I'd expect false, the same as an item linking to / without the anchor.

What seems to happen in Structure::isParent():

isAncestorOf() stripping fragments looks intentional (UrlTest::ancestorProvider() covers it), so the problem is that the two checks treat the fragment differently.

In 5.x, isAncestorOf() didn't strip the fragment from the ancestor, so this didn't happen.

A URL that's only a fragment, like #contact, ends up the same way: it's stripped to /, and the $url === '#' check only catches a bare #.

How to reproduce
  1. Create a navigation and use Add → Add Nav Item to add a text link (not "Link to Entry") with the URL /#contact.

  2. Output it with the nav tag:

    {{ nav:main }}
      {{ title }}: {{ is_parent ? 'parent' : 'not parent' }}
    {{ /nav:main }}
    
  3. Visit any page other than the home page. The /#contact item shows parent.

On a multisite with the site URL /de, the same happens with /de#contact.

Logs

Environment
Environment
Laravel Version: 12.73.0
PHP Version: 8.4.28
Composer Version: 2.11.1
Environment: local
Debug Mode: OFF
Maintenance Mode: OFF
Timezone: UTC
Locale: de_CH

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: database
Database: mysql
Logs: stack / daily
Mail: ses
Queue: sync
Session: file

Storage
REMOVED

Locales
Installed: de, de_CH, en, fr, it
LaravelLang\Actions\Plugin: 1.13.1
LaravelLang\Attributes\Plugin: 2.16.3
LaravelLang\HttpStatuses\Plugin: 3.13.1
LaravelLang\Lang\Plugin: 15.31.1
LaravelLang\MoonShine\Plugin: INCORRECT
LaravelLang\StarterKits\Plugin: 1.14.1
Locales Version: 2.11.0
Protected: de, de_CH
Publisher Version: 16.8.0

Livewire
Livewire: v3.8.9

Spatie Permissions
Features Enabled: Default
Version: 6.25.0

Statamic
Addons: 4
License Key: Set
Sites: 3 (REMOVED, REMOVED, REMOVED)
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 6.42.0 PRO

Statamic Addons
marcorieser/statamic-livewire: 5.3.5
stillat/antlers-components: 2.8.0
[REMOVED PRIVATE 1+2]
Installation

Fresh statamic/statamic site via CLI

Additional details

Possible fix in Structure::isParent(): strip the query string and fragment before comparing with the site root, and skip any URL that starts with #:

if (Str::startsWith($url, '#')) {
    return false;
}

if ($this->siteAbsoluteUrl === URL::removeQueryAndFragment($absoluteUrl)) {
    return false;
}

Workaround for now: {{ if is_parent && ! (url | contains('#')) }} in the template.

Similar to #5269 (empty URLs flagged as parent in 3.2.x).

主要语言
PHP
星标
4.9k
派生
647
平均合并
1 天 45 分钟
30 天内合并 PR
221

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

statamic/cms 的其他 Issue

查看 statamic/cms 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。