express.static正在处理根url请求。 例如我想做一个快速从https://example.com到https://example.com/dashboard的重定向。 检查下面的情况,第一个工作,第二个不工作。我希望第二个也能工作。有人知道为什么express.static处理根url请求
案例1(作品)
app.get('/', (req, res, next) => {
res.redirect('/dashboard');
})
app.use(express.static(path.join(__dirname, 'dist')))
app.get('/dashboard', (req, res, next) => {
//do stuff
})
案例2(不为我工作)
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
})
改变DIST到/ DIST应该使其工作 – itsundefined