Nested sub-routes question #186
-
Can you provide an explanation of the valid routes that the second example on the Sub-routing documentation page would provide? I fear I am not understanding the intended effect of it. At the time of this writing, below is the example code I am referring to. I have added comments mimicking the first example with my understanding and what actually happens. $app->group('/user', function () use($app) {
// will result in '/user/'
$app->get('/', function () use($app) {
$app->response()->markup('no user id');
});
// will result in '/user/12'
$app->get('/(\d+)', function ($id) use($app) {
$app->response()->markup("user $id");
});
// I would have thought this would correspond to '/user/settings'
// However, this actually mounts onto the root path '/settings/'
$app->mount('/settings', function () use($app) {
// will result in '/settings/privacy' when I expected '/user/settings/privacy'
$app->get('/privacy', function () use($app) {
$app->response()->markup('Privacy Settings');
});
// will result in '/settings/notification' when I expected '/user/settings/notification'
$app->get('/notification', function () use($app) {
$app->response()->markup("Notification Settings");
});
});
}); |
Beta Was this translation helpful? Give feedback.
Answered by
mychidarko
Apr 26, 2023
Replies: 1 comment 7 replies
-
If this works as intended and not how I imagine then perhaps it would be nice to pass the current route path into the callback function that you pass into $app->group('/user', function () use($app, $routePrefix1) {
// $routePrefix1 would be equal to '/user' here
// I would have thought this would correspond to '/user/settings'
// However, this actually mounts onto the root path '/settings/'
$app->mount("$routePrefix1/settings", function () use($app, $routePrefix2) {
// $routePrefix2 would be equal to '/user/settings' here however in this case it is not needed
// will result in '/settings/privacy' when I expected '/user/settings/privacy'
$app->get('/privacy', function () use($app) {
$app->response()->markup('Privacy Settings');
});
});
}); |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's been fixed now, so you can update Leaf and your issue should be fixed