Angular 2.0深度链接不起作用。 地址栏也一样

一切工作正常,当我build立和导航应用程序中的链接,但在地址栏中键入不! 最终,我希望能够通过电子邮件发送链接到特定的应用程序页面/path,我不知道如何实现。

我遵循了angular度路由器指南文档 。 我正确地认为…

我使用NodeJS(与快递),并在服务器中,我已经redirect到应用程序根的所有stream量。

app.get("*", function(req, res) { console.error("in get *") res.redirect("/"); }); 

在我的index.html中我已经设置了基地

 <base href="/"> 

我有我的客户端path/path设置如下

 const appRoutes: Routes = [ { path: 'vendor/registration', component: VendorRegistrationComponent }, { path: 'vendors', component: VendorListComponent }, { path: '', redirectTo: 'vendor/registration', pathMatch: 'full' }, { path: '**', component: PageNotFoundComponent } ]; 

如果我在浏览器地址栏中键入http://localhost:8080/vendors ,则可以访问http://localhost:8080/vendor/registration ,这是有道理的,因为这是服务器告诉浏览器redirect到的地方。

那么我应该如何深入链接到我的应用程序?

编辑。 Angular教程 – “英雄之旅” – 也performance出同样的行为。 即在浏览器的地址栏中直接inputurl不起作用。 该应用程序显示“正在加载…”的文本,并没有路由到控制器。

你的问题的答复是在angular2文档中明确描述的

通常你不需要在服务器上redirect,因为你的所有路由都是由客户端上的angular路由器处理的。

相反,使您的所有快速路线总是为所有请求的url提供index.html 。 当客户端应用程序引导时,angular将根据请求的url来照顾到适当的组件。 确保保持您的<base href="/">标签,以便angular度可以知道URL的哪一部分路由。

 const path = require('path'); app.get("*", function(req, res) { res.sendFile(path.join(__dirname, '/path/to/your/index.html')); });