admin管理员组文章数量:1335402
I want to access the localhost:3000/admin which is in my views .. the index.html and the admin.html are my two different base files one is for users and the other is for admin dashboard respectively
in my app.routes.js I have this
angular.module('appRoutes', ['ngRoute'])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'app/views/pages/home.html',
controller: 'MainController',
controllerAs: 'main'
})
.when('/admin', {
templateUrl: 'app/views/admin.html',
})
.when('/logout', {
templateUrl: 'app/views/pages/home.html'
})
.when('/login', {
templateUrl: 'app/views/pages/login.html'
})
.when('/signup', {
templateUrl: 'app/views/pages/signup.html'
})
.when('/admin/login' ,{
templateUrl: 'app/views/pages/adminlogin.html'
})
$locationProvider.html5Mode(true);
})
in server.js I have this
app.get('*', function(req, res){
res.sendFile(__dirname + '/public/app/views/index.html');
});
there are two html index files: index.html, admin.html i want to open admin.html when the url is: localhost:3000/admin
and index.html when the url is: localhost:3000
screenshot of the app structure
in views/pages I have all the html pages required by index.html and admin.html using ng-view
I want to access the localhost:3000/admin which is in my views .. the index.html and the admin.html are my two different base files one is for users and the other is for admin dashboard respectively
in my app.routes.js I have this
angular.module('appRoutes', ['ngRoute'])
.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'app/views/pages/home.html',
controller: 'MainController',
controllerAs: 'main'
})
.when('/admin', {
templateUrl: 'app/views/admin.html',
})
.when('/logout', {
templateUrl: 'app/views/pages/home.html'
})
.when('/login', {
templateUrl: 'app/views/pages/login.html'
})
.when('/signup', {
templateUrl: 'app/views/pages/signup.html'
})
.when('/admin/login' ,{
templateUrl: 'app/views/pages/adminlogin.html'
})
$locationProvider.html5Mode(true);
})
in server.js I have this
app.get('*', function(req, res){
res.sendFile(__dirname + '/public/app/views/index.html');
});
there are two html index files: index.html, admin.html i want to open admin.html when the url is: localhost:3000/admin
and index.html when the url is: localhost:3000
screenshot of the app structure
in views/pages I have all the html pages required by index.html and admin.html using ng-view
Share Improve this question edited Feb 20, 2019 at 10:50 Jeppe 2,2964 gold badges28 silver badges40 bronze badges asked Jun 6, 2016 at 22:45 Sahil ChauhanSahil Chauhan 1851 silver badge13 bronze badges 5- Please state what you're asking about, as currently it's not clear what is the problem. – Dmitriy Khudorozhkov Commented Jun 6, 2016 at 22:48
- Possible hint for you: stackoverflow./questions/24927784/… – Dmitriy Khudorozhkov Commented Jun 6, 2016 at 22:49
- stackoverflow./questions/16906231/… – Dmitriy Khudorozhkov Commented Jun 6, 2016 at 22:49
- @DmitriyKhudorozhkov i want to access localhost:3000/admin.. localhost:3000 is just working fine , it is rendering index.html file – Sahil Chauhan Commented Jun 6, 2016 at 22:50
- Consider reading this; 1st answer contains the answer to your question. – Dmitriy Khudorozhkov Commented Jun 6, 2016 at 23:00
2 Answers
Reset to default 5As I understand your question, you would want to just add one more routing rule to express. Express uses the first route that matches, so order is important here.
app.get('/admin/*', function(req, res){
res.sendFile(__dirname + '/public/app/views/admin.html');
});
app.get('*', function(req, res){
res.sendFile(__dirname + '/public/app/views/index.html');
});
The angular docs state about html5mode that you should rewrite all your urls to a single app entry point: Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html).
https://docs.angularjs/guide/$location#server-side
So to be clear: What I suggest is that you create server-routes for two separate apps. Nothing prevents you from using the first app one more time on another route, but I would advice against it. Separate anything with real power over your backend from the public app. I.e. remove /admin/login
and /admin
from your ng-routes and simply create a separate app for that.
I found a better solution for this..
app.get('*', function(req, res){
if (req.url.match('^\/admin')) {
res.sendFile(__dirname + '/public/app/views/admin.html');
} else {
res.sendFile(__dirname + '/public/app/views/index.html');
}
});
本文标签: javascriptHow to use multiple index pages in angularjsStack Overflow
版权声明:本文标题:javascript - How to use multiple index pages in angularjs - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742387001a2465234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论