嗯,这样的方法可能适用于您的场景:
- 在您的特快JS中创建一条全面的路由.(这意味着如果它没有命中任何定义的路由,则此路由将捕获它)
- 在这个处理程序中,通过添加一些上下文(比如将目标URL作为查询字符串附加),将其重定向到index.html路径
- 在您的Angular 根页面中,捕获以下查询字符串并导航到目标Angular 页面
它可能看起来像这样:
特快专线
const url = require("URL");
app.get('*', function (req, res) {
res.redirect(url.format({
pathname:"/", // assuming that index.html lies on root route
query: {
"navigateTo": req.url,
}
}));
})
角形APP根组件
// assuming this is the root component
@Component({ ... })
export class AppComponent implements OnInit {
constructor(private route: ActivatedRoute, private router: Router) { }
ngOnInit() {
this.route.queryParams
.subscribe(params => {
const { navigateTo } = params;
if (navigateTo)
{
this.router.navigateByUrl(navigateTo);
}
}
);
}
}