17

My angular application is hosted in server in which the application url is http://xyz.domain.in (Example Url). Now I created sub directory inside it to host another application. But when i try to access the path like http://xyz.domain.in/subfolder , getting this in console.

Error: Cannot match any routes. URL Segment: 'subfolder'

Base href of the application in subfolder is

<base href="./subfolder">

How to accomplish this?

James Z
  • 12,209
  • 10
  • 24
  • 44
Manush
  • 1,852
  • 7
  • 26
  • 39
  • Possible duplicate of [Develop Angular App in Sub-Directory](https://stackoverflow.com/questions/42742152/develop-angular-app-in-sub-directory) – Eliya Cohen Jun 22 '18 at 12:55

5 Answers5

41

You have to specify the path of your subfolder when launching a build :

ng build --base-href=/subfolder/
Artory
  • 845
  • 7
  • 13
10

do not need to mention the subfolder name, if you are depolying at subfoler you need to mention only href="./"

harish kushwaha
  • 111
  • 1
  • 3
  • This seems to work, so to me this looks like a useful answer. **To the person who downvoted this:** please explain why an answer might not be a viable option in your opinion or tell the person who posted it what you think is missing in the comment section below the post.. do not just give it a random downvote. – Johannes Aug 28 '20 at 12:10
  • This works for me too. Probably the best answer here. Thanks! – Tom - Lunabee.com Oct 01 '20 at 13:23
  • maybe the user could write a more complete answer, explaing that you have to change the tag to in index.html file, but yes, it works very well. – Murilo Góes de Almeida Oct 09 '20 at 15:50
1

build into subfolder:

ng build --prod --output-path="dist/subfolder" --deployUrl="subfolder/"

https://floyk.com/en/wall/status/BX

Igor Simic
  • 510
  • 4
  • 4
0

You need to add pathMatch to your routes like so:

{path: 'url', component: YourComponent, pathMatch: 'subfolder'},
Eliya Cohen
  • 10,716
  • 13
  • 59
  • 116
  • This would not solve the issue. The issue experienced is from serving multiple apps over a single domain and the angular app living in a subdirectory on the server. See answer below – mr.pribesh Nov 18 '21 at 01:52
-1

To properly setup an Angular app on a subdirectory:

  1. Update the angular.json to include the baseHref property under the build options. ie:
...
build": {
  "builder": "@angular-devkit/build-angular:browser",
  "options": {
    "baseHref": "/subdirectory1/subdirectory2",
  1. Update the index.html base href:
<base href="/subdirectory1/subdirectory2">
  1. Ensure useHash is NOT set in your app routing module's ExtraOption (since the default is false)

  2. Update image and style links. any absolute image links should be made relative

ex. FROM: src="/assets/img/pic.jpg" TO: src="assets/img/pic.jpg"

scss ex.

FROM: background-image: url('/assets/img/pic.jpg TO: background-image: url('../../../assets/img/pic.jpg

mr.pribesh
  • 187
  • 1
  • 13