我的角度应用程序有多个页面,用户可以访问,我想隐藏所有其他网址,只向用户显示基本网址.所以想象一下我的基本网址是:www.example.com,我还有其他网页,如关于,联系我们等.目前,当用户点击关于时,网址会更改为www.example.com/about.角度是否可以不添加“/ about”?这是否可以使用角度js?另外,我一直在寻找解决方案,并尝试过ui-router.js,这个模块也可以吗?
解决方法
如果您使用的是ui-router,那么您可以定义状态而无需指定URL
myApp.config(function($stateProvider,$urlRouterProvider) { // // For any unmatched url,redirect to /state1 $urlRouterProvider.otherwise("/state1"); // // Now set up the states $stateProvider .state('state1',{ url: "/state1",templateUrl: "state1.html",controller: 'Controller3' }) .state('state2',{ templateUrl: "state2.html",controller: 'Controller2' }) .state('state3',{ templateUrl: "state3.html",controller: 'Controller3' }) });
所以默认情况下,url将是/ state1.您可以在模板中使用ui-sref指令实现导航,例如ui-sref =“state2”或在控制器中使用$state服务,如$state.go(‘state2’).