【发布时间】:2015-09-09 03:00:57
【问题描述】:
当用户转到 localhost:8888 或 localhost:8888/ 时,我的 Angular 应用程序将 url 更改为 http://localhost:8888/#!/
这是我在主页中的 Angular 应用:
app.config(['$locationProvider', '$routeProvider',
function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider
.when('/', {
redirectTo: ((window.status === 'signup') ? '/signup' : '/signin')
})
.when("/signin", {
templateUrl: "/public/user/signin.html",
controller: "signinController"
})
.when('/signup', {
templateUrl: "/public/user/signup.html",
controller: "signupController"
})
.otherwise({
redirectTo: '/'
});
}
])
如果用户转到http://localhost:8888/auth,角度重定向到http://localhost:8888/auth#!/signin,
仅当用户转到 http://localhost:8888/auth/ 时,角度重定向到 http://localhost:8888/auth/#!/signin
app.config(['$locationProvider', '$routeProvider',
function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider
.when('/', {
redirectTo: ((window.status === 'signup') ? '/signup' : '/signin')
})
.when("/signin", {
templateUrl: "/public/user/signin.html",
controller: "signinController"
})
.when('/signup', {
templateUrl: "/public/user/signup.html",
controller: "signupController"
})
.otherwise({
redirectTo: '/'
});
}
])
angular官网和大部分书籍推荐使用xxx/#!/xxx格式。我怎样才能做到这一点?
编辑:我知道我可以从服务器端添加斜杠。但用户可以直接输入xxx.com/auth。
为什么xxx.com 工作但xxx.com/auth 不工作?
Edit2:教程示例项目适用于所有 url。我们有几乎相同的实现
http://angular.github.io/angular-phonecat/step-8/app/#/phones
尝试输入http://angular.github.io/angular-phonecat/step-8/app(不带斜杠
【问题讨论】:
标签: angularjs