I needed to create a route in which the path of the route would be completely dynamic and so I created a routing callback.
<?php
namespace Drupal\uber_affiliate\Routing;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
/**
* Class EntityOverview
*
* @package Drupal\uber_affiliate\Routing
*/
class AffiliateRoute {
/**
* Dynamically generate the routes for the entity details.
*
* @return \Symfony\Component\Routing\RouteCollection
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function routes() {
$affiliate_menu_path = \Drupal::state()->get('affiliate_module_affiliate_menu_path', 'affiliate');
$routes = [];
$routes['affiliate'] = new Route(
$affiliate_menu_path . '/' . '{aff_id}' . '/' . '{dest_path}' . '/' . '{tracker_id}',
[
'_controller' => 'Drupal\uber_affiliate\Controller\UberAffiliate::affiliate_page',
],
[
'_permission' => 'track affiliate clicks for this role',
],
);
return $routes;
}
}
I need {dest_path} and {tracker_id} to be optional. How do I make them optional?