zendframework / zend-router

Standalone routing implementation for HTTP and console requests
BSD 3-Clause "New" or "Revised" License
32 stars 20 forks source link

Segment optional parameters with childs #19

Closed pobidowski closed 8 years ago

pobidowski commented 8 years ago

The issue was given here: http://stackoverflow.com/questions/12713029/zf2-optional-route-constraints-in-child-routes

It's very weird behavior. If I want to build a system with optional multilanguage support (where all links are prefixed by "/languageCode/"), it is not possible to acomplished with child routes.

weierophinney commented 8 years ago

This is by design.

For a child route to match, the full parent must match, including optional segments. This is not a bug, but because doing otherwise is quite difficult to accomplish, and prone to error.

The solution as presented on that SO post is correct: create an alternate route for the case where you want the child to match when no optional segments are available in the parent.