Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngRouteNames applied to all routes in app #2

Open
im1dermike opened this issue Nov 17, 2015 · 9 comments
Open

ngRouteNames applied to all routes in app #2

im1dermike opened this issue Nov 17, 2015 · 9 comments

Comments

@im1dermike
Copy link

My app uses .NET MVC routes for unauthenticated pages, but once a user has been authenticated, they enter Angular SPA land where I had originally been using the built-in $routeProvider. I accomplish this by applying the ng-view directive in the view for the only authenticated MVC route in my app (Home/Index).

I've implemented ngRouteNames to this app and the route naming works great. The problem I just noticed is that when I go to the unauthenticated pages outside of my Angular routing, it somehow ends up applying routing to it.

Any idea why it would be doing this?

@stakach
Copy link
Member

stakach commented Nov 17, 2015

hmm do you have an otherwise block in your $routeProvider?
Something like:

    $routeProvider.otherwise({
        redirectTo: '/'
    });

What is the effect of caused when you visit routes outside of the app?

@im1dermike
Copy link
Author

Yes.

.otherwise(
{
    templateUrl: 'Content/templates/404.html'
});

@stakach
Copy link
Member

stakach commented Nov 17, 2015

What happens when you visit an unauthenticated page?

@im1dermike
Copy link
Author

It's the .when('/', {}) home route that it's running...

@stakach
Copy link
Member

stakach commented Nov 17, 2015

So the home / root route is defined?
What is the effect of routes running when you are on that page?

@im1dermike
Copy link
Author

The problem is that the home route has a number of dependencies in it's resolve definition. When you're on unauthenticated pages now, it incorrectly thinks it's on the home route (when it shouldn't be running the route code at all) and tries to resolve the dependencies. The dependencies for that route require the user to be authenticated and fail when they run when unauthenticated.

@stakach
Copy link
Member

stakach commented Nov 17, 2015

hmm.. You might have to check if authenticated in the resolve code.
Then, if the route doesn't change when authenticated, $watch or $on authentication run the code.

I'm not sure you can turn off routes

@im1dermike
Copy link
Author

This is something the ngRouteNames directive is doing. The second I remove it, it works a expected. I'm not really inclined to do much rewriting of my code because of route naming.

@stakach
Copy link
Member

stakach commented Nov 17, 2015

I'll have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants