It seems like your goal is to dynamically set the templateUrl
based on the values of :file
and :page
in the $stateParams
.
Although you haven't provided details on how you are using $state.go
, I have created an example that demonstrates different ways to switch between states with or without { reload: true }
.
angular.module('exampleApp', ['ui.router'])
.config(function($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/file1/page1');
$stateProvider
.state('edit', {
url: '/:file/:page',
controller: 'FilePageCtrl',
templateUrl: function($stateParams) {
return $stateParams.file + "-" + $stateParams.page + ".html";
}
});
})
.controller('FilePageCtrl', function($scope, $state) {});
Below are some sample links that trigger state changes but do not re-execute the controller and template if they are already in the current state:
<a ui-sref="edit({ file: 'file1', page: 'page2' })">/file1/page2</a>
This can also be achieved inline with ng-click
or within a controller:
<a href ng-click="$state.go('edit', { file: 'file1', page: 'page2' })">/file1/page2</a>
The following two examples will force the controller and templateUrl to execute, regardless of whether the current state matches:
<a ui-sref="edit({ file: 'file1', page: 'page2' })" ui-sref-opts="{ reload: true }">/file1/page2</a>
<a href ng-click="$state.go('edit', { file: 'file1', page: 'page2' }, { reload: true })">/file1/page2</a>
To learn more about using dynamic templateUrl, you can visit this link: https://github.com/angular-ui/ui-router/wiki#templates
For a live demo, check out this working example: http://plnkr.co/edit/JUgUB3I675Kh7kKkitgJ?p=preview