Skip to content
This repository has been archived by the owner on Sep 20, 2020. It is now read-only.

Otherwise "/" #124

Closed
raphaelluchini opened this issue Dec 26, 2014 · 14 comments
Closed

Otherwise "/" #124

raphaelluchini opened this issue Dec 26, 2014 · 14 comments

Comments

@raphaelluchini
Copy link

Hello,

When I use a futureState url:'/' and otherwise('/') the router isn't calling otherwise. When I use only url:'/home' works.

Example:

var state = {
      'stateName': 'home',
      'url': '/',
      'templateUrl': 'template.html',
      'type': 'async'
    };

$urlRouterProvider.otherwise('/');
$futureStateProvider.futureState(state);

I've tried to fix, and now it's working, but there are some tests failing, when I get time I'll try to fix them.

@christopherthielen
Copy link
Owner

Can you put this example into a plunk for me?

@raphaelluchini
Copy link
Author

Sorry, I forgot to mention this bug occurs with html5Mode enabled. Here an example http://plnkr.co/edit/qPBD4M0k6g8y3p95cTqP

@christopherthielen
Copy link
Owner

@raphaelluchini I downloaded your plunk, enabled HTML5 mode, and launched a http server (npm install -g http-server; http-server -p 8889)

  • I loaded index.html (http://localhost:8889)
  • It redirects me to http://localhost:8889/other
  • I click "Goto Undefined Page" (http://localhost:8889/undefined)
  • Otherwise is invoked
  • It brings me to "Home" page (http://localhost:8889).

@raphaelluchini
Copy link
Author

Yes!, you are correct, but try to type directly in the brower: http://localhost:8889/undefined
We got Not found :(

@christopherthielen
Copy link
Owner

@raphaelluchini
Do you have redirect rules in place on the server-side for HTML5 mode? It should be serving the contents of index.html when you request /undefined from the server. If you get a 404 Not found, angular isn't even loaded yet, so it can't possibly intercept the location change. Is the app loaded, then you type in /undefined in the browser?

Give me exact steps on how can I reproduce what you are seeing.

Also, you say you can type "/undefined" directly into the location bar and it works fine if you set otherwise to "/home", for instance, correct?

This kind of information would have been nice in the original bug report :)

@raphaelluchini
Copy link
Author

Are you correct again :P We are getting 404 because this http-server does not support redirect rules.

I'm using nginx to staging and browserSync to dev environment, this bug occurs in both cases.

Anyway I'll create a sample in a repository with browerSync configurations or if do you have experience with nginx I also could include as well.

@christopherthielen
Copy link
Owner

I don't know either browserSync nor nginx, so go with whatever is easiest to set up.

@raphaelluchini
Copy link
Author

Ok, about your last question, the bug occurs when we have any url:"/" route setted, and doesn't matter what otherwise is setted.

@christopherthielen
Copy link
Owner

Interesting. Get that browserSync config added to the plunk and give me step by step instructions to reproduce. Thanks!

@raphaelluchini
Copy link
Author

Ok, I got it, actually there is another trick, this bug only appears with "/" setted and with async requests, I've created a sample with setTimeout only to test, in my current project I'm using require(Webpack).

Here the example https://github.com/raphaelluchini/ui-router-extras-otherwise-bug

run npm install and then gulp serve

;)

@raphaelluchini
Copy link
Author

Type /something, going to work, then change the 'url': '/home', to 'url': '/' and otherwise to "/", and then try again /something

@christopherthielen
Copy link
Owner

Made some progress. This same bug can be triggered from your example when home is mapped to url: '/home' by typing http://localhost:3000/home/something in the browser URL.

This has something to do with futurestate url's having .* appended to them (so you can add an entire module as a futurestate and navigate to /module/arbitrarily/deeply/nested/url).

So typing in /home/something matches /home.* and triggers lazy loading of the futurestate home, then does a urlRouter.sync(). However, when sync() fails to match /home$, it calls .otherwise(). Finally, future state's .otherwise is in "transitionPending" mode and ignores the transition.

@raphaelluchini
Copy link
Author

Awesome! I can't wait to be released :) When do you plan to release it?

Thanks!

@christopherthielen
Copy link
Owner

@raphaelluchini 0.0.12 released. Also please responde in #140

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

No branches or pull requests

2 participants