Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

useAsDefault route option doesn't work when no routes were matched. #415

Open
d-ph opened this issue May 15, 2016 · 0 comments
Open

useAsDefault route option doesn't work when no routes were matched. #415

d-ph opened this issue May 15, 2016 · 0 comments

Comments

@d-ph
Copy link

d-ph commented May 15, 2016

Angular docs link say:

The useAsDefault property on the HeroList Route Definition, indicates 
that if no other Route Definition matches the URL, then this Route Definition should be 
used by default.

but when I mark a route as useAsDefault and go to an invalid url hash-address, then nothing happens.

Steps to reproduce:

  1. Download the component router demo app from plunker
  2. Extract the zip file and start your favourite web server for the downloaded folder (e.g. php -S localhost:8080)
  3. Edit app.js and change $locationProvider.html5Mode(false); to $locationProvider.html5Mode(true);. This is not strictly required, but this is what I did.
  4. Go to localhost:8080. Result: You are correctly redirected to http://localhost:8080/#/crisis-center
  5. Go to http://localhost:8080/#/heroes. Result: the Heroes component is correctly loaded.
  6. Manually change the url to say: http://localhost:8080/#/foo-bar

Result:
Nothing happens. The url now says http://localhost:8080/#/foo-bar, but the application still shows the Heroes page.

Expected result:
Application redirects to the useAsDefault route, which is http://localhost:8080/#/crisis-center

More info:
When I change this:

if ((isBlank(parsedUrl) || parsedUrl.path == '') && possibleMatches.length == 0) {
  return PromiseWrapper.resolve(this.generateDefault(parentComponent));
}

into this:

if ((isBlank(parsedUrl) || parsedUrl.path == '') || possibleMatches.length == 0) {
  return PromiseWrapper.resolve(this.generateDefault(parentComponent));
}

in angular_1_router.js, then it works. If I was to fix that properly though, I would put

if (possibleMatches.length == 0) {
  return PromiseWrapper.resolve(this.generateDefault(parentComponent));
}

straight after

var possibleMatches = _aux ? rules.recognizeAuxiliary(parsedUrl) : rules.recognize(parsedUrl);

. But I don't actually know, where the ts file for that source is.

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

No branches or pull requests

1 participant