Closed johntmyers closed 9 years ago
@johntmyers a couple questions, what version of the generator did you use? Also, mind posting your .yo-rc.json
file?
generator-angular-fullstack@2.1.1
{
"generator-angular-fullstack": {
"insertRoutes": true,
"registerRoutesFile": "server/routes.js",
"routesNeedle": "// Insert routes below",
"routesBase": "/api/",
"pluralizeRoutes": true,
"insertSockets": true,
"registerSocketsFile": "server/config/socketio.js",
"socketsNeedle": "// Insert sockets below",
"filters": {
"babel": true,
"js": true,
"html": true,
"css": true,
"uirouter": true,
"bootstrap": true,
"uibootstrap": true,
"socketio": true,
"mongoose": true,
"auth": true,
"oauth": true,
"googleAuth": true,
"facebookAuth": true
}
},
"generator-ng-component": {
"routeDirectory": "client/app/",
"directiveDirectory": "client/app/",
"filterDirectory": "client/app/",
"serviceDirectory": "client/app/",
"basePath": "client",
"moduleName": "",
"filters": [
"uirouter"
],
"extensions": [
"babel",
"js",
"html",
"css"
],
"directiveSimpleTemplates": "",
"directiveComplexTemplates": "",
"filterTemplates": "",
"serviceTemplates": "",
"factoryTemplates": "",
"controllerTemplates": "",
"decoratorTemplates": "",
"providerTemplates": "",
"routeTemplates": ""
}
}
Try this:
--- .run(function ($rootScope, $location, Auth) {
+++ .run(function ($rootScope, $state, Auth) {
// Redirect to login if route requires auth and you're not logged in
$rootScope.$on('$stateChangeStart', function (event, next) {
Auth.isLoggedInAsync(function(loggedIn) {
if (next.authenticate && !loggedIn) {
event.preventDefault();
--- $location.path('/login');
+++ $state.go('login');
}
});
});
});
Yep, that works. Should we be using $state when using ui-router then?
We should, and it has actually been taken care of in the canary
branch: https://github.com/DaftMonk/generator-angular-fullstack/commit/6aadee6d956cefb9a787eb0851d287654dfca111#diff-11
I'll close this, as the solution has been posted and fixed in dev branch
I saw that back in Sep there was PR #683 ... when I scaffold out a new app, browsing to /settings actually brings me to a blank page, the redirect never happens.
When I remove the
event.preventDefault();
it works just fine.