📜  ngRoute和ui-router有什么区别?

📅  最后修改于: 2021-05-13 18:41:46             🧑  作者: Mango

ngRoute: ngRoute是由AngularJS团队开发的模块,该团队是AngularJS核心的一部分。这是一个模块,可以更好地管理基本方案,而更少的复杂性则可以更好地处理。

ui-router: ui-router是在AngularJS项目之外制作的框架,用于增强和改进路由功能。这是一个框架,因此它将帮助您组织项目界面的各个部分

两者都具有独特的功能,取决于您的项目在它们之间进行选择。您必须知道哪一个对您的工作项目更有用,在提供这两项功能的下方,这将清除您的想法,您应该为项目选择哪一个。

ngRoute ui-router
The ngRoutr is good for smaller app where you do not need to inherit the pages from other sections. The ui-router is effective for the larger application becouse it allows nested-views and multiple named-views, it helps to inherit pages from other sections.
In the ngRoute have to change all the links manually that will be time consuming for the larger applications, but smaller application nrRoute will perform faster. In the ui-router it allows strong-type linking between states so if you change any one place link that will change the links every where. That has to be used by ui-sref.
The router provider for the ngRoute $routeProvider The router provider for the ngRoute $stateProvider $urlRouterProvide
The template view for the ngRoute is ng-view which is better compare to ui-view. The tempalte view for the ui-router ui-view much powerfull for multipage inherit from other sections.
You can’t determine if you are in state. You can easily determine if you are in a state or parent of a state to adjust UI element within your templates via $state provided by ui-router which you can expose via setting it in $rootScope on run.
The router start event for the ngRoute $routeChangeStart The router start event for the ngRoute $stateChangeStart
To get Params as a service in the ngRoute $route -> $route.cuurent.params.id and $routeParams -> $routeParams.id To get Params as a service in the ui-router $state -> $state.params.id and $stateParams -> $stateParams.id
The ngRoute organized arround the URL routes. The ui-router organized arround states routes.

结论:两者在当地都表现更好,它们之间的选择取决于您的项目。如果您的项目应用程序包含复杂视图,那么我将首选ui-router而不是ng-Route,否则还有很多其他功能将以某种方式帮助您构建项目。如果您的项目包含不太复杂的视图,则可以自由选择。