剔除使用URL路径AngularJS [英] Excluding path in url using AngularJS
问题描述
我的角度应用程序有哪些用户可以访问,我想隐藏其他所有网址,只显示用户的基本URL多个页面。所以,想象一下我的基本网址为:www.example.com和我有其他的网页喜欢,联系我们等。目前,当用户点击一下,网址更改为www.example.com/about~~V。有可能是角度不添加/约?这是可能的采用了棱角分明的js?另外,我一直在寻找解决方案,并与UI的router.js试验,是否也可以用这个模块?
My angular application has multiple pages which users can visit and I would like to hide all other urls and only show users the base url. So imagine my base url is: www.example.com and I have other pages like About, Contact Us etc. Currently, when the user clicks on About, the url changes to www.example.com/about. Is it possible for angular not to add the "/about"? Is this possible using angular js? Also, I have been searching for solutions and have experimented with ui-router.js, is it also possible with this module?
推荐答案
如果您正在使用的用户界面的路由器,那么你可以定义状态,而无需指定如
If you are using ui-router, then you can define states without specifying urls like
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.go('STATE2')
。
So by default the url will be /state1. And you can implement navigation by using ui-sref directive in your template like ui-sref="state2"
or using $state service in your controller like $state.go('state2')
.
这篇关于剔除使用URL路径AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!