express.static handling root url request

Viewed 3074

express.static is handling the root url request. e.g. I want to do a redirect in express from https://example.com to https://example.com/dashboard. Check the cases below, first one works, second does not. I expect the second to work too. Anyone knows why?

Case 1 (works)

app.get('/', (req, res, next) => {
   res.redirect('/dashboard');
})    

app.use(express.static(path.join(__dirname, 'dist')))

app.get('/dashboard', (req, res, next) => {
   //do stuff
}) 

Case 2 (does not work for me)

app.use(express.static(path.join(__dirname, 'dist')))

//request doesn't come here 
app.get('/', (req, res, next) => {   
   res.redirect('/dashboard')
})

app.get('/dashboard', (req, res, next) => {
  //do some stuff
}) 
1 Answers
Related