menu
up-caret
down-caret

Next.js

A place to chat about Next.js and answer questions. For all other ZEIT products, check this out.

# General

General Chatter

Trending conversations
I am trying to add React OWL Carousel.
@adilsaeed31 · 7h
pages, best practices and anti-patterns
@markymark · 10h
next-routes not working with next 7 ?
@kokno · 12d
How should a nested layout be implemented?
@seekcx · 40d
Using a sub-folder when running a custom express server
@madsobel · 40d

How to add a default redirect for `/static/` routes if not found?

Suman Kundu (@devsumanmdn) · December 1, 2018 at 6:21am

How to add a default redirect for `/static/` routes if not found?

December 1, 2018 at 6:21am

Let's say i have static/icons/{name.svg} , for some reason if the {name.svg} is not present there I want to respond with static/icons/default.svg, how to achieve this with custom-express-server?


December 1, 2018 at 7:53am

I would add an nginx rule...

  • reply
  • like

This seems like the best solution

<img
src={"/static/icons/someIcon.svg"}
onError={ ({target}) => {
target.onerror=null;
target.src='/static/icons/default.svg';
}}
/>
Edited
  • reply
  • like

Nothing to do with Next.js

  • reply
  • like