0

I am using Angular ui-router and defined my routes. But the problem is it changes the state but also changes the url which is not really the intention of using ui-router. I am not sure what I am doing wrong here, need some suggestion on below code

app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {

        $urlRouterProvider.otherwise('/');

        $stateProvider
            .state('ManageUser', {
                url: '/manager-user',
                templateUrl: '/app/user/manage_users.html'
            })
            .state('ManageUserSetting', {
                url: '/user-setting',
                templateUrl: '/app/user/settings_normal.html'
            });
    }]);

1 Answer 1

2

If you want to change state without also changing the URL it's as simple as just omitting the url parameter from the relevant state:

    $stateProvider
        .state('ManageUser', {
            url: '/manager-user',
            templateUrl: '/app/user/manage_users.html'
        })
        .state('ManageUserSetting', {
            templateUrl: '/app/user/settings_normal.html' // url is still '/manager-user/'
        });



That said, in most cases when using angular-ui-router you will want to change the URL. The main purpose of angular-ui-router is to be able to nest views and then be able link directly to those view states.

(Watch this video for an explanation on the differences between ui-router and ngRoute)

If in the case which you describe above you merely want to display some user settings inside a nested view, without changing the URL, you might actually be better off using ng-show to toggle the settings. The choice is yours.

Here is an example where I've mixed the two. If you'd like a detailed explanation let me know.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.