Redirect doesn't work

In templates/Users/login.php I have:
<?= $this->Html->link("Add User", ['action' => 'add']) ?>

When I click on the link provided, it doesn’t redirect me to the users add page.

The redirect shows up in the URL like this:

http://localhost/users/login?redirect=%2Fusers%2Fadd

but it doesn’t go the add page.
I am using cakephp version 4

As that’s come straight from the example login: -
https://book.cakephp.org/4/en/tutorials-and-examples/cms/authentication.html#adding-login
It may be possible you missed a step defined there in your app.

What does happen when you click on that link?

I know this feeling though, I build the sample app many many times, each time so I could understand a bit more of how the guts work. I can only suggest the hard slog of starting CMS tut all over again. When you get it working as it should, do a WinMerge comparison of what didn’t work last time (so make a copy of what you have now) to work out what what you missed - then you’ll better understand the thinking required.

Once the tut works perfectly you could try to change it to suit your purposes, one step at a time (so you know the last change if something breaks). And don’t forget to clear the cache after any change to a table or entity.

I found what I missed:
If you try to visit /users/add without being logged in, you will be redirected to the login page. We should fix that as we want to allow people to sign up for our application. In the UsersController fix the following line:

// Add to the beforeFilter method of UsersController $this->Authentication->addUnauthenticatedActions(['login', 'add']);

Nicely done, that’s exactly what’s needed.
You’ll note at the bottom of the CMS tut page it is mentioned there: -
https://book.cakephp.org/4/en/tutorials-and-examples/cms/authentication.html#enabling-registrations