Use param in $urlRouterProvider.when to dynamically rewrite route

What I am trying to accomplish is to re-write the url from /userType1/' to '/userType1/something/'
where ‘something’ is dynamic and based on the value userType1.
Ideally I could pass the {userType} param into the function getRouteFromUserType and use the result of that function.

Basically I have code quite similar to this

(function() {
    'use strict';

    angular.module('myModule').config(['$stateProvider', '$urlRouterProvider', userRoutes]);

    function userRoutes($stateProvider, $urlRouterProvider) {
      $urlRouterProvider.when(`/{userType}/{userCode}`, `/{userType}/{userCode}/${getRouteFromUserType('{userType}')}`);

Obviously passing in ‘{userType}’ isn’t working, it just passes in the literal string, can how I use {userType} as a parameter/lookup or have some logic based on the value.

Go to Source
Author: MrEs