Login Page Without Index.html Design - Ngroute (angularjs)
Solution 1:
Given the situation above looks like you want two page layout (page design or page template), the first one is now used in index.html
, and the second one you want to use in login.html
which just has two fields to fill out. So angular-ui/ui-router
(doc url: https://github.com/angular-ui/ui-router/wiki) could be the solution to this issue.
The idea behind that is ui-router
has a very powerful tool named ui-view
which you can see it as a layout or template. So when the path is on any page other than login page like /index
or /home
use one ui-view
, and on /login
page then use another different ui-view
.
For a rough example: index.html page:
<html><head></head><body><divui-view="layout"></div></body></html>
I assume you will reuse the head part, so just wrap every thing from the body in the original index.html
and put into the new index.html
. Same to the login page login.html
.
config file:
$stateProvider.state('index', {
url:'/index',
views: {
layout: {
templateUrl:"/path/to/index.html"
}
},
controller:'indexController'
}
.state('login', {
url:'/login',
views: {
layout: {
templateUrl:"/path/to/login.html"
}
},
controller:'loginController'
})
So what does the code above do is very similar to what you did with $routeProvider
, it defines on which url
use which controller
and to load which view
.
Hope this can help you, if any question let me know please.
Solution 2:
You need to create your login page as a diferente ngApp, store your sesion on the localSotarge in case of a successfull login and then redirect to you main ngApp.
In your main ngApp, validate if a session exists in the localStorage and redirecto to the loginApp if it dont.
I know it sounds a bit like overdoing stuff, but I have not found any other solution in my 3 years working with AngularJS. Now, keep in mind that this is necesary because you need to NOT TO APPLY your index.html, and the only way to do that is using another ngApp.
Solution 3:
Routing is used for injecting views in angular SPA. What I get from from your question is you need a login dialog.
For that you may look ngDialog
or uibDialog
Solution 4:
In your case you need to load new layout. I understand, for login and for application there is mostly different layout. This operation is equal to redirecting page to new location. With new angular app and controllers for login. You can use:
$window.location.href="new/layout/template"
.
Read more @ Angular Dev Docs.
Post a Comment for "Login Page Without Index.html Design - Ngroute (angularjs)"