How to replace authentication links with custom routes? I am working on a custom Drupal 8 module that has its own authentication form. 

For this, I created a Drupal page with the custom authentication form, i.e. I have a route at drupalsite.com/custom-signup

What I am not able to figure out is how can I replace Drupal's default Register and Login links which are scattered everywhere on the website to point to above route. I don't want to redirect from /user/login page to /custom-signup as I still want to allow admin to login. For all other users except admins should be redirected to \custom-signup. 

I could use jquery to brute-force my way to replace the links, but is there an efficient way to achieve this?

TL;DR: I need to replace following default Drupal links using my module. 



Update:

Following the first solution, I added the routing files as follows, the links are redirecting me to my custom form.  



However, when I try to enter user/login manually in the URL, I get page not found message on the website.
You need to alter the route, in your custom module add:

mymodule/src/Routing/RouteSubscriber.php

namespace Drupal\mymodule\Routing;

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

/**
 * Listens to the dynamic route events.
 */
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    // Change path '/user/login' to '/customn-login'.
    if ($route = $collection-&gt;get('user.login')) {
      $route-&gt;setPath('/custom-login');
    }
    // Change path '/user/register' to '/custom-signup'.
    if ($route = $collection-&gt;get('user.register')) {
      $route-&gt;setPath('/custom-signup');
    }
  }

}


mymodule/mymodule.services.yml

services:
  mymodule.route_subscriber:
    class: Drupal\mymodule\Routing\RouteSubscriber
    tags:
      - { name: event_subscriber }


For more in depth information, see Altering existing routes and adding new routes based on dynamic ones.



If you still want /user/login to work, then you can create a new route for it. 

mymodule/mymodule.routing.yml

mymodule.login:
  path: '/user/login'
  defaults:
    _form: '\Drupal\user\Form\UserLoginForm'
    _title: 'Log in'
  requirements:
    _user_is_logged_in: 'FALSE'
  options:
    _maintenance_access: TRUE


Remember to clear all caches to see changes.