angular是google开发的一个单页面应用框架,是现在比较主流的单页面应用框架之一.该强大的地方有很多,比如双向数据绑定,应用了后端的mvc模式到前端,自定义指令等.
既然是单页面应用,肯定离不开页面的切换.我们首先来说一下angular的路由.
angular实现页面切换时用了route.
angular.min.js要在angular-ui-router.min.js之前加载.然后我们就要在app中注册了.
(function () {angular.module('demo', ['ui.router', ])})();
注册完之后就需要配置route了
function config($stateprovider, $urlrouterprovider,$httpprovider) {$urlrouterprovider.otherwise(/home/get);$stateprovider.state('login', {url: /login,templateurl: ../views/login.html,}).state('home', {abstract: true,url: /home,templateurl: views/common/content.html,}).state('home.get', {url: /get,templateurl: views/get.html,data: { pagetitle: 'example view' }}).state('home.post', {url: /post,templateurl: views/post.html,data: { pagetitle: 'example view' }});}app = angular.module('demo');app.config(config);
配置到这里就配置完了.配置中的每一个state就一个view,表示一个页面,页面跳转用state,对应的html文件在templateurl对应的文件中.
以上所述是小编给大家分享的angularjs中route的使用方法和配置的相关知识,希望对大家有所帮助。