[英]Remove template name from URL AngularJS
我正在使用angularJS $ routeProvider,
//模板
//路由
function ($routeProvider) {
$routeProvider.
when('/_profileView', {
templateUrl: '_profileView.htm',
controller: '_profileViewController'
}).
when('/', {
templateUrl: '_homeView.htm',
controller: '_homeViewController'
}).
when('/_homeView', {
templateUrl: '_homeView.htm',
controller: '_homeViewController'
})}
有沒有辦法像這樣從Url中刪除模板名稱:Example.com/#/_homeView ----> Example.com/
如果您使用ui.router
而不是ng-route
,它將解決您的問題。 例如:
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"
})
});
在url
屬性中,如果只給出"/"
則結果就是您所需要的。
關於使用ui.router
而不是ng-route
另一個說明 -我經歷過,如果您想使用嵌套的ng-view
-s,那么只有ui.router
可能。
我希望這會有所幫助,加油!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.