What is the difference between $state.go(app.location) and $location.path(“app/location”)?

前端 未结 3 1376
猫巷女王i
猫巷女王i 2020-12-24 06:02

I have recently started using ionic framework, it has angular js in it. To navigate between screens, I was using $location.path and it\'s working great. However, in an examp

3条回答
  •  猫巷女王i
    2020-12-24 06:26

    The $location service is on the angular.js framework out of the box and allow you to manage location object (similar to that in pure javascript). The $state service is a part of ui-router module and allows you to manage routes in an advanced mode, throughout a state machine management of views.

    If you use ui-router, you should prefer to use $state service to manage states/routes because state abstracts the concept of route and you could change the physical routes without changing states.

    Besides that, more problems you could have if you run in hashbang mode, in particular in your html links. In this case it's preferable to use ui-sref rather than ng-href (or just href). In my opinion, you should always think in term of states rather than paths. Obviously you can mix the services if you know what you're doing

提交回复
热议问题