0

In my Angular10 project, I have a folder in my assets (declared in angular.json) that I don't want to be navigated if you type the full url in the browser.

But still it has to be usable if I use it in my code ex:

<img src="./assets/brand/logo.png"> <- This shows the logo

http://localhost:4200/assets/brand/logo.png <- If I type this in the browser it should redirect me on the homepage

Can I achieve this with the app-routing.module.ts?

EDIT: Ok, Thanks! Now I understand I cannot achieve this by using angular.

I will use Docker with Nginx to serve the application. Is it possible to achieve this with Nginx?

cjd82187
  • 3,468
  • 3
  • 15
  • 19
user2026121
  • 35
  • 1
  • 8
  • This is a server issue, not a client (Angular) issue. If you need to be able to access that file from your app you may have trouble blocking it from being opened from the URL directly. It would help if we knew what backend service you are using. – cjd82187 Jul 21 '20 at 14:43
  • @cjd82187 I was short on details I'm sorry, I've edited the question. I will use docker with Nginx – user2026121 Jul 27 '20 at 12:06
  • This is an nginx specific question. I've tagged it as such and changed the tittle. My only nginx experience has been googling what I needed and hoping for the best. I'm almost positive what you want (directly going to that URL in the browser and redirecting, but still allowing the browser to request that image in your template) is not possible, but I'll let someone with more experience answer. – cjd82187 Jul 27 '20 at 12:36

1 Answers1

0

If you are typing the URL in the browser, then it is not Angular anymore. The request goes directly to the server and it is up to the server to serve it or not. Angular Router will only react to route changes coming form browser events such as clicking a button and an anchor tag... etc

Answering this question depends on what technology is used in the server to serve the image (Nginx, Cloudfront, Spring... etc).

Aboodz
  • 1,549
  • 12
  • 23