I also needed a page at /contact
path. With a simple custom module you can change the default routing for the contact forms.
Let's assume custom module is called: example
and the new default for the contact forms will be /contactform
instead of /contact
:
example.services.yml
services:
example.route_subscriber:
class: Drupal\example\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
src/Routing/RouteSubscriber.php
<?php
// Save this file as `src/Routing/RouteSubscriber.php` in your module directory.
namespace Drupal\example\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
// Change the core's default path for `/contact` so that we can use it as an alias.
if ($route = $collection->get('contact.site_page')) {
$route->setPath('/contactform');
}
if ($route = $collection->get('entity.contact_form.canonical')) {
$route->setPath('/contactform/{contact_form}');
}
}
}