[英]Remove template name from URL AngularJS
I am using angularJS $routeProvider, 我正在使用angularJS $ routeProvider,
//Template //模板
//Routing //路由
function ($routeProvider) {
$routeProvider.
when('/_profileView', {
templateUrl: '_profileView.htm',
controller: '_profileViewController'
}).
when('/', {
templateUrl: '_homeView.htm',
controller: '_homeViewController'
}).
when('/_homeView', {
templateUrl: '_homeView.htm',
controller: '_homeViewController'
})}
Is there a way to remove the template name from the Url like this: Example.com/#/_homeView ----> Example.com/ 有没有办法像这样从Url中删除模板名称:Example.com/#/_homeView ----> Example.com/
If you would use ui.router
instead of ng-route
it would solve your problem. 如果您使用ui.router
而不是ng-route
,它将解决您的问题。 For example: 例如:
angular.module('app',[ 'ui.router' ])
.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider.state('home', {
url : "/",
templateUrl : "_homeView.htm",
controller: "_homeViewController"
}).state('profile', {
url : "/_profileView",
templateUrl: "_profileView.htm",
controller: "_profileViewController"
})
});
Inside the url
attribute if you give just "/"
the outcome is just what you need. 在url
属性中,如果只给出"/"
则结果就是您所需要的。
Another note on using ui.router
instead ng-route
-- I experienced that, if you want to use nested ng-view
-s it's possible only with ui.router
. 关于使用ui.router
而不是ng-route
另一个说明 -我经历过,如果您想使用嵌套的ng-view
-s,那么只有ui.router
可能。
I hope this helps, cheers! 我希望这会有所帮助,加油!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.