Skip to content

[Routing] Exception/default value required when navigating to route with a optional parameter with "!" character #47583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MichaelBelgium opened this issue Sep 15, 2022 · 1 comment

Comments

@MichaelBelgium
Copy link

Symfony version(s) affected

5.4.8

Description

This is odd and I'm sure this is not the way to go.

When navigating to a route with an optional parameter that has the "!" character (which means the default value will always be included in the generate function) you're required to pass that default parameter when navigating to it.

Which means the optional parameter doesn't have any purpose. As you're required to type it or it throws a ResourceNotFoundException

How to reproduce

Using the example from the announcement blogpost

  1. Define the route
/**
 * @Route("/blog/{!page}", name="blog_list")
 */
public function list($page = 1)
{
    // ...
}
  1. Go to /blog
  2. Have a ResourceNotFoundException
  3. /blog/1 does work but default parameter loses its purpose

Possible Solution

No response

Additional Context

No response

@Tobion
Copy link
Contributor

Tobion commented Oct 29, 2022

I don't think this is a bug. The ! declarares the parameter as non-optional for matching. So the default value is only used for generating URLs but not for matching.
The reason is explained in #29599 (comment)

@Tobion Tobion closed this as completed Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants