Trailing Slash on Slim 4 Skeleton

After installation

composer create-project slim/slim-skeleton myslimsite

I added Trailing Slash Middleware

composer require middlewares/trailing-slash

Then I added the below line to app\middleware.php


use App\Application\Middleware\SessionMiddleware;
use Slim\App;

use Middlewares\TrailingSlash;

return function (App $app) {
    $app->add(new TrailingSlash(false));

to remove the trailing slash from url, but it returns a 404 when accessing /users/

How to get this working?

Here is example with adding slash to all requests:

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Exception\HttpNotFoundException;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Psr7\Response as PsrResponse;
use Middlewares\TrailingSlash;

require __DIR__ . '/../slim/vendor/autoload.php';

$app = AppFactory::create();

$app->add(new TrailingSlash(true));

$app->get('/user/', function (Request $request, Response $response) {
        return $response;


/user and /user/ work well.

Do you add TrailingSlash(false) after $app->addRoutingMiddleware(); ?