【发布时间】:2019-11-19 12:33:11
【问题描述】:
我在前端使用 Angular 并从节点服务器(Express)返回简单的 301 响应
`
app.get('/', (req, res) => {
res.redirect(301, 'http://localhost:4200/second')
});
`
我的路线是:
`
export const routes: Routes = [
{path: '',component: HelloComponent},
{path: 'third',component: ThirdPageComponent},
{path: 'second',component: SecondPageComponent}
];
`
我正在从http://localhost:4200/third 重定向到http://localhost:4200/second,但不是重定向,而是出现错误(404),但http://localhost:4200/second 路由工作正常。
【问题讨论】:
-
你已经有了第三个组件?
-
@NiallMitch14 如果没有发生重定向,我会在那里看到该组件,我认为它不会以任何方式影响重定向。
-
@KrunalShah 我不认为它与节点有关,因为当我直接从浏览器点击该端点时,正在发生重定向。
-
@pawanbhatt 如果您尝试将 localhost:4200/test 作为您的 URL,那么重定向是否有效?