Home > OS >  Route of Angular 15, how to show raw *.json file into browser
Route of Angular 15, how to show raw *.json file into browser

Time:01-23

A want to show raw JSON file in my Angular 15 frontend similar to ordinary Html logic

<a href="../api/XXXXX/YYYYY.json" target="_blank">JSON</a>

but I have app-routing.module.ts

const routes: Routes = [
   { path: '', component: HomeComponent, pathMatch: 'full' },
   { path: 'welcome', component: WelcomeComponent, canActivate: [AuthGuard] },
   ...]

and this module forbid to do this simple operation.

ERROR Error: Uncaught (in promise): Error: NG04002: Cannot match any routes. URL Segment: 'api/aes/wrongParameters.json'
 

In this relative path "api/XXXXX/YYYYY.json" I have a lot of JSON files and I need to allow show any of it.
How its possible?

CodePudding user response:

I suggest you to put the json files in your asset folder then do

 <a href="/assets/myjson.json" target="_blank">JSON</a>
  • Related