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

Skip to content

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

Closed
@MichaelBelgium

Description

@MichaelBelgium

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

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