I found there’s a route in my site that could only be reached if I type the trailing slash:
$app->group('/foo', function (RouteCollectorProxy $group) {
$group->get('/', Pages\Foo::class); // 👈 This one
$group->any('/logs.html', Pages\Foo::class . ':logs');
$group->get('/scripts.html', Pages\Foo::class . ':scripts');
});
I fixed it by duplicating the route definition. It works, but it feels ugly.
$group->get('/', Pages\Foo::class);
$group->get('', Pages\Foo::class);
I also tried out out the middlewares/trailing-slash package linked in the Trailing / in route patterns chapter of Slim cook book to normalise trailing slashes in paths (I’ll probably force removal) but I can’t see that it makes any difference. I’ve tried adding it first and last, and nothing seems to happen. No redirection happens.
I found this snippet in the forum, but it throws ArgumentCountError in current version. It probably has an easy fix, but this silly issue is starting to get time consuming for me.
How do people deal with trailing slashes and canonical paths in Slim v4?