How do we replace the token  in a custom module? I am using the following in my custom module but the token is not being replaced. Is this a namespace issue?

$token_service = \Drupal::token();
$post_login = $token_service-&gt;replace('&lt;front&gt;');
As already mentioned, &lt;front&gt; is a route, not a token, so you can't use the token API to work with it.

You can resolve it using the Url class:

$path = \Drupal\Core\Url::fromRoute('&lt;front&gt;')-&gt;toString();

// $path is equal to '/'


But I'm not sure how useful that will be. Perhaps you want to get the front page that's set in config instead:

$path = \Drupal::config('system.site')-&gt;get('page.front');