{"id":1766,"date":"2022-08-30T15:19:16","date_gmt":"2022-08-30T15:19:16","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/02\/how-do-you-prefix-a-url-route-with-a-dynamic-scope-value-after-being-called-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:19:16","modified_gmt":"2022-08-30T15:19:16","slug":"how-do-you-prefix-a-url-route-with-a-dynamic-scope-value-after-being-called-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-do-you-prefix-a-url-route-with-a-dynamic-scope-value-after-being-called-collection-of-common-programming-errors\/","title":{"rendered":"How do you prefix a URL route with a dynamic $scope value after being called?-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to prefix my users&#8217; usernames to the routes they call within my application after they&#8217;ve logged in. How would I achieve this in angular? I already tried using the $locationProvider and prefixing it but it isn&#8217;t dynamic. I need to have it be dynamic accepting a value stored in the $rootScope but since the $rootScope is a service and not a provider it can&#8217;t be injected into the provider config function. How do I achieve this prefix?<\/p>\n<pre><code>kmApp.config(['$routeProvider', '$locationProvider',\nfunction ($routeProvider, $locationProvider) {\n    $locationProvider.html5Mode(false).hashPrefix('username');\n    $routeProvider\n    .when('\/campaign\/create\/:campaignid', {\n        templateUrl: 'modules\/campaign\/views\/edit.html',\n        controller: 'kmApp.modules.campaign.editAction'\n    })\n    .when('\/campaign\/view', {\n        templateUrl: 'modules\/campaign\/views\/index.html',\n        controller: 'kmApp.modules.campaign.indexAction'\n    })\n    .when('\/campaign\/edit\/:campaignid', {\n        templateUrl: 'modules\/campaign\/views\/edit.html',\n        controller: 'kmApp.modules.campaign.editAction'\n    })\n    .when('\/dashboard', {\n        templateUrl: 'modules\/dashboard\/views\/index.html',\n        controller: 'kmApp.modules.dashboard.indexAction',\n        resolve: {\n            routeChange: function ($q, $rootScope, $location) {\n                var defer = $q.defer();\n                if ($rootScope.UserData.clientName !== undefined) {\n                    $location.hash($rootScope.UserData.clientName);\n                }\n                defer.resolve();\n                return defer.promise;\n            }\n        }\n    })\n    .when('\/settings', {\n        templateUrl: 'modules\/config\/views\/index.html',\n        controller: 'kmApp.modules.config.indexAction'\n    })\n    .when('\/login', {\n        controller: 'kmApp.controller.rootLayout'\n    })\n    .when('\/addClient', {\n        templateUrl: 'modules\/clients\/views\/index.html',\n        controller: 'kmApp.modules.clients.indexAction'\n    })\n    .when('\/kmAdmin', {\n        templateUrl: 'modules\/clients\/views\/clientadmin.html',\n        controller: 'kmApp.modules.clients.clientAdmin'\n    })\n    .when('\/kmAdmin\/digitalProp\/:clientId', {\n        templateUrl: 'modules\/clients\/views\/digitProp.html',\n        controller: 'kmApp.modules.clients.digitPropAction'\n    })\n    .when('\/kmAdmin\/distribution\/:clientId', {\n        templateUrl: 'modules\/clients\/views\/distribution.html',\n        controller: 'kmApp.modules.clients.distributionAction'\n    })\n    .when('\/changePassword', {\n        templateUrl: 'modules\/config\/views\/changePassword.html',\n        controller: 'kmApp.modules.config.changePassword'\n    })\n    .otherwise({\n        redirect: ':clientName\/dashboard'\n    });\n} ]);\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-12-02 01:20:32. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am trying to prefix my users&#8217; usernames to the routes they call within my application after they&#8217;ve logged in. How would I achieve this in angular? I already tried using the $locationProvider and prefixing it but it isn&#8217;t dynamic. I need to have it be dynamic accepting a value stored in the $rootScope but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1766","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1766"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1766\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}