Reputation: 109
I'm trying out the http request function in Angular. However, I figured that I'm unable to access any local file in my project folder. When I access "localhost:4200/testfile.json", it throws me an error:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'starter/testfile.txt'
Then I looked into the router module and couldn't figure out what the problem is. Here's the code for routermodule:
imports: [
RouterModule.forRoot([
{ path: '', redirectTo: 'starter', pathMatch: 'full' },
{ path: 'starter', component: StarterComponent },
])],
I also tried to put the file into assets folder and used localhost:4200/assets/testfile.txt to access it, which works. I'm wondering why assets is the only folder that allows the access while all other path doesn't work. Is it the problem with my routermodule?
Thank you so much.
Upvotes: 1
Views: 2417
Reputation: 60596
I assume you are using the Angular CLI? The CLI looks for pieces in very specific folders. If you want it to look in other folders for content, you can modify the angular.cli.json file.
For example:
"assets": [
"assets",
"api",
"favicon.ico"
],
This assets array tells the CLI to look in both an assets folder and an api folder. You can add whichever other folders you want.
Upvotes: 2