How to implement a button with different redirections? I'm setting up a job directory using Drupal 8, together with a team.
It is possible to see it here.

As you can see below, in a screenshot of the site, there's a button called "Add new job":



In a more visual way, this is what I would like to implement:


If the user doesn't have login:


User clicks button
User goes to create account

Else:


User clicks button
User goes to a specific / different page / view



Something is triggering me that we can achieve this like that using Rules, setting on action events, but I'm not sure how.

It can be that I am totally wrong and there's a more straightforward way to do this.

For example, if I was to implement this just with PHP, would redirect a button to one page and in that page, using user sessions sessions and if conditions, would define the content showing up.

I'm not an expert in Drupal neither I'm aware of all of its possibilities. So, any help is appreciated.
Point the button to a custom controller:

namespace Drupal\mymodule\Controller;

use Drupal\Core\Controller\ControllerBase;

class ExampleController extends ControllerBase {

  /**
   * Controller for action button.
   */
  public function action() {

    // if user is not logged in, redirect to create a new account
    if ($this-&gt;currentUser()-&gt;isAnonymous()) {
      return $this-&gt;redirect('user.register');
    }

    // else return content or redirect to content
    return ...;
  }

}