Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Sub-routes in Main route not getting static files ExpressJS

// Make the href or the src absolute path instead of a relative path 
// by adding / at the beginning of the path

// before - relative path
<link rel="stylesheet" href="stylesheets/style.css"> 
// dependent on which route you are visiting
// on http://localhost:3000/article/create, it will search for style.css
// in the http://localhost:3000/article/stylesheets/style.css url
// which is wrong ( not the public directory )

// after - absolute path
<link rel="stylesheet" href="./stylesheets/style.css">
// independent of which route you are visiting
// will always search for your files in the public directory
// Courtesy: Sadeen Alaa - https://stackoverflow.com/users/11689488/sadeen-alaa
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Main #route #static #files #ExpressJS
ADD COMMENT
Topic
Name
9+3 =