i want access localhost:3000/admin in views .. index.html , admin.html 2 different base files 1 users , other admin dashboard respectively
in app.routes.js have
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 have this
app.get('*', function(req, res){ res.sendfile(__dirname + '/public/app/views/index.html'); });
there 2 html index files: index.html, admin.html want open admin.html when url is: localhost:3000/admin
and index.html when url is: localhost:3000
in views/pages have html pages required index.html , admin.html using ng-view
as understand question, want add 1 more routing rule express. express uses first route matches, order 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 html5mode should rewrite urls single app entry point: using mode requires url rewriting on server side, have rewrite links entry point of application (e.g. index.html).
https://docs.angularjs.org/guide/$location#server-side
so clear: suggest create server-routes two separate apps. nothing prevents using first app 1 more time on route, advice against it. separate real power on backend public app. i.e. remove /admin/login
, /admin
ng-routes , create separate app that.