Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f756164

Browse files
docs(guide/location): include section on base[href]
Closes #14018
1 parent 5f8eb4d commit f756164

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/content/guide/$location.ngdoc

+17-2
Original file line numberDiff line numberDiff line change
@@ -330,22 +330,37 @@ reload to the original link.
330330
### Relative links
331331

332332
Be sure to check all relative links, images, scripts etc. Angular requires you to specify the url
333-
base in the head of your main html file (`<base href="/my-base">`) unless `html5Mode.requireBase` is
334-
set to `false` in the html5Mode definition object passed to `$locationProvider.html5Mode()`. With
333+
base in the head of your main html file (`<base href="/my-base/index.html">`) unless `html5Mode.requireBase`
334+
is set to `false` in the html5Mode definition object passed to `$locationProvider.html5Mode()`. With
335335
that, relative urls will always be resolved to this base url, even if the initial url of the
336336
document was different.
337337

338338
There is one exception: Links that only contain a hash fragment (e.g. `<a href="#target">`)
339339
will only change `$location.hash()` and not modify the url otherwise. This is useful for scrolling
340340
to anchors on the same page without needing to know on which page the user currently is.
341341

342+
342343
### Server side
343344

344345
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links
345346
to entry point of your application (e.g. index.html). Requiring a `<base>` tag is also important for
346347
this case, as it allows Angular to differentiate between the part of the url that is the application
347348
base and the path that should be handled by the application.
348349

350+
### Base href constraints
351+
352+
The `$location` service is not able to function properly if the current URL is outside the URL given
353+
as the base href. This can have subtle confusing consequencies...
354+
355+
Consider a base href set as follows: `<base href="/base/">` (i.e. the application exists in the "folder"
356+
called `/base`). The URL `/base` is actually outside the application (it refers to the `base` file found
357+
in the root `/` folder).
358+
359+
If you wish to be able to navigate to the application via a URL such as `/base` then you should ensure that
360+
you server is setup to redirect such requests to `/base/`.
361+
362+
See https://github.com/angular/angular.js/issues/14018 for more information.
363+
349364
### Sending links among different browsers
350365

351366
Because of rewriting capability in HTML5 mode, your users will be able to open regular url links in

0 commit comments

Comments
 (0)