How do I get the current path of a block?
Yes, this is because of block caching. The block is built once for the first request and then will stay in the cache forever, until you clear the cache.

You have to set a cache context on the url path:

'#cache' =&gt; ['contexts' =&gt; ['url.path']],


Then the block will get a cached version for every path.