Using SubdomainRoute with cakephp 3

I am trying to use subdomains with cakephp 3, it works a bit, but there are a couple of things that still do not work properly. I have searched for some topics, but they are for cakephp 2.* so not up to date.

I created a file (SubdomainRoute.php) in Lib/Route (had to create those folder as they didn’t exist), looks like this:

class SubdomainRoute extends CakeRoute {

    public function match ($params) {
        $subdomain = isset($params['subdomain']) ? $params['subdomain'] : null;
        unset($params['subdomain']);
        $path = parent::match($params);
        if ($subdomain) {
            $path = 'http://' . $subdomain . '.localhost' . $path;
        }
        return $path;
    }
}

And then in the routes.php, I added ‘subdomain’ => ‘admin’ (for the pages that need to have the admin subdomain) and does show those pages on subdomain, but they are not forced to use that subdomain (I can still access the same page without subdomain).

Also when I create a link in the page, it adds ?subdomain=admin to the url, why is that and can that be ignored?

Cheers

Does anyone have an idea?