-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Add Route Annotation : explicit_defaults #28633
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
Conversation
Allows generator to add default values to generated URL in order to get a canonical one
what about a new path syntax to do this:
|
I like @ro0NL's idea to deal with this at the param syntax level. |
My original idea was to have a canonical URL generated.
Having the option on the parameter level gives more flexibility but IMO defeats the purpose of the canonical URL. (BTW, the next step I had in mind was having the Router sending a Redirect when it matches a route on a non-canonical form.) |
we can debate if redirecting non-canonical to canonical URLs is something that belongs to core 🤔 if so, that might also be triggered by e.g. |
The generated URL is already a canonical one to me. I get you'd like it to have the suffix in it instead. It's not about canonical 1/0 to me, but about suffix 1/0, isn't it? |
@chs2 WDYT about these proposals? Would you like to implement it? |
I'd like to but I can't get my head around the param syntax especially with the XML/XSD. |
@chs2 i dont think we need canonical:true|false, as @nicolas-grekas mentioned each configured route is/should be already a canonical one. So the options are:
news_export:
path: '/exports/news.{_format}'
defaults:
_format: xml
news_export_non_canonical:
path: '/export/news'
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
defaults:
route: news_export_xml
news_export_xml:
path: '/exports/news.xml' These are explicit configurations to show we dont need If we look at option 2, we see our missing step: it cant specify the That's what we should solve by the proposed news_export_non_canonical:
path: '/export/news'
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
defaults:
route: news_export
news_export:
path: '/exports/news.{!_format}'
defaults:
_format: xml Due |
Allows generator to add default values to generated URL
in order to get a canonical one
If a route has a parameter with default value when it gets generated this parameter is not included
$uri
is/exports/news
which is identical, from the router point of view, to/export/news.xml
.URIs should be unique to avoid duplicate content, which is bad for SEO.
Though it is possible to always add default value to parameters (
$router -> generate('news_export', ['_format' => 'xml', ])
), the added "explicit_defaults" ensures the route will always generated to a canonical form.