verbb / navigation

A Craft CMS plugin to create navigation menus for your site.
Other
90 stars 23 forks source link

{{node.link}} returns wrong URL for singles #320

Closed lenvanessen closed 1 year ago

lenvanessen commented 2 years ago

Describe the bug

When you assign a single to a navigation node on a multisite environment, the wrong url is returned. I have a single page called "resources" and the urls are

/de/resources /en/resources /nl/resources

However, every language returns the /resources url. We only have this problem with singles

Steps to reproduce

1) Create a menu 2) render with the following snippet

<ul class="header__list">
                    {% for node in craft.navigation.nodes('main').with(['children.children']).level(1).all() %}
                    <li class="header__list-item">
                        {{ node.link({class: 'header__list-link '~(node.hasDescendants ? 'js-menu-toggle')}) }}

                        {% if node.hasDescendants %}
                        <ul class="header__submenu">
                            {% for subnode in node.children %}
                            <li>
                                {{ subnode.link({class: 'js-menu-toggle'}) }}
                                {% if subnode.hasDescendants %}
                                <ul class="header__submenus">
                                    {% for child in subnode.children %}
                                        <li>{{ child.link }}</li>
                                    {% endfor %}
                                </ul>
                                {% endif %}
                            </li>
                            {% endfor %}
                        </ul>
                        {% endif %}
                    </li>
                    {% endfor %}
                </ul>
            </nav>

3) test between different domains

Craft CMS version

4.2.7

Plugin version

2.0.6

Multi-site?

yes

Additional context

No response

engram-design commented 2 years ago

What is your navigation "Propagate nodes across all enabled sites?" setting?

Can you confirm if the the "Base URL" settings for each of your sites determine the language, or is it the URL for the single entry.

For example, do you have your single setup like the below with the language included in the URL for the single:

image

Or is that managed by your site's URL and the URL for your resources single is just resources?

image

Either way, that renders as expected on my tests, but I'm keen to see what your propagation settings are, and if you manage the navigations per-site. If you do (manage nodes per-site), you'll want to ensure you're picking the correct single entry for the appropriate site. If you don't, then it should resolve to the correct node for the site you're currently on.

engram-design commented 1 year ago

Can you confirm the above setup is different or the same to yours?

lenvanessen commented 1 year ago

@engram-design I have the latter, the key is just resources and the domain is managed by the site. Screenshots below. I can send you a db + composer.json if it helps?

Schermafbeelding 2022-11-11 om 20 01 30

r

Schermafbeelding 2022-11-11 om 20 01 54
engram-design commented 1 year ago

What are you "Propagation Method" settings for the navigation?

I've spun up a fresh install, replicating your setup, and all is looking correct to me. Each resources page I'm just doing a:

{{ craft.navigation.render('mainMenu') }}

And my mainMenu just contains a single node, which is the resources entry. Propagation is set to Save nodes to all sites enabled for this navigation. And because I have the Title of the resources entry to be translated, each site I toggle the navigation's site for, I can see the updated title.

On the front-end, the link in the navigation is pointing to the correct site.

It might help if you can send some files our way, best to send them to web at verbb.io.

engram-design commented 1 year ago

Closing due to inactivity.

lenvanessen commented 1 year ago

Sorry, forgot to follow up. I could still send over Some files, but the issue was resolved by removing and re-adding the node

engram-design commented 1 year ago

All good! We'll keep this around to see if it crops up again.