-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Otherwise functinality like $routeProvider #208
Comments
You can inject $urlRouterProvider in the same place you inject $stateProvider and configure it like this:
angular.js is in a bit of flux when it comes to treatment of appBase as they try to work out the kinks of operating in html5 and hash mode and dealing with subdirectories... it's a strangely difficult challenge. Is the issue just that you didn't know about $urlRouterProvider or that you're struggling with the path of the redirect?.... only asking because I know it's confusing and want to make sure which issue(s) is (are) relevant to you. |
I saw some references in comments to urlRouterProvider but did not see it mentioned in the docs so I am trying to figure out the best way to replicate the functionality in angular $routeProvider as a first step to migrating an app to use ui-router. So is the syntax the same? Does urlRouterProvider support the redirectTo: property $urlRouterProvider.otherwise({redirectTo: "/demo/app/home"}); Or do I need to use some other syntax to get the same result of redirecting any unmatched urls to a specified url |
What did you try that didn't work? |
I tried (javascript version of the coffeescript) $urlRouterProvider.otherwise({ And I get this error Uncaught Error: 'rule' must be a function from MainApp router.js:425 I find it somewhat confusing that the example you example code above https://github.com/angular-ui/ui-router/blob/0.0.1/sample/index.html#L54 begs the question of when to use one versus the other etc. |
So I played around and it appears that this syntax works $urlRouterProvider.otherwise("" + base + "/app/home"); In other words urlRouterProvider does not support the {redirectTo: url}) signature like routeProvider |
I'm glad you figured it out. I wish it were simpler, too! :) Give ui-router a chance... it might take a little change but I bet you'll find it worth your while! |
I found the following in another comment. It should be in the docs or example as standard practice as many will be migrating from routeProvider and want the simplest use case that maps. Use $stateProvider to set up all your states and then $urlRouterProvider to set up a single otherwise. $urlRouterProvider.otherwise("/"); // this will send any non-valid url back to "/' Also if using angular-unstable 1.1.5 will need to add
See http://stackoverflow.com/questions/17200231/how-to-set-default-url-route Thanks for the help. |
That was my stack overflow answer. It's a quirk in Angular 1.1.5 and has nothing to do with ui-router and nothing to do with "otherwise" functionality, even though the question was posed that way. |
Flagging this as a docs issue for @timkindberg. |
@SmithSamuelM Is this able to be closed now? |
Yes |
define(['angular', 'app'], function(angular, app) {
}); |
this is what you looking for: |
What part is the "otherwise" |
How do I implement the equivalent of the angular $routeProvider ".otherwise" route
as a catchall to any other urls that user might input?
as in
.otherwise redirectTo: "#{base}/app/home"
The text was updated successfully, but these errors were encountered: