【发布时间】:2017-09-13 17:44:40
【问题描述】:
express.static 正在处理根 url 请求。 例如我想通过快递从https://example.com 重定向到https://example.com/dashboard。 检查以下情况,第一个有效,第二个无效。我希望第二个也能工作。有谁知道为什么?
案例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 应该可以正常工作