Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Routing] Routes with host/locale matrix not working correctly #38209

Closed
@Wirone

Description

@Wirone

Symfony version(s) affected: 5.1.5

Description
I've followed #30617 (and symfony/symfony-docs#13571) for configuring support for locales based on host. When I access page through host mapped to non-default locale, page still renders in default locale.

How to reproduce

# config/routes.yaml
foo:
    resource: routes/foo.yaml
    prefix: /
    defaults:
        _format: html
    host:
        en: 'foo.loc'
        pl: 'pl.foo.loc'
# config/routes/foo.yaml
app.foo.landing_page:
    path: /
    methods: [GET]
    controller: App\Foo\LandingPageAction

With config above RedirectableCompiledUrlMatcher has this route collection for this path:

# var/cache/dev/url_matching_routes.php
'/' => [
    [['_route' => 'app.foo.landing_page', '_controller' => 'App\\Foo\\LandingPageAction'], null, ['GET' => 0], null, false, false, null],
    [['_route' => 'app.foo.landing_page', '_controller' => 'App\\Foo\\LandingPageAction', '_locale' => 'en', '_format' => 'html'], 'foo.loc', ['GET' => 0], null, false, false, null],
    [['_route' => 'app.foo.landing_page', '_controller' => 'App\\Foo\\LandingPageAction', '_locale' => 'pl', '_format' => 'html'], 'pl.foo.loc', ['GET' => 0], null, false, false, null],
],

Unfortunately, the first one is matched when I access page via pl.foo.loc, so locale is not set and page displays in default locale.

ℹ️ When I comment out first rule, matching hosts work and locale is set properly.

Maybe I do something wrong but mentioned docs are not merged so support for this feature is somehow undocumented 😉

Possible Solution
Move non-strict rule (without host matching) to the end of the collection for path, so it can run as fallback if other rules (hosts) aren't matched.


CC: @odolbeau

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions