angular2新路由器未从URL加载

时间:2016-06-30 19:31:22

标签: angular2-routing

我刚从router-deprecated升级到“@ angular / router”:“3.0.0-alpha.8”。我在应用程序内部工作正常,但在导航到URL时无法正常工作。

例如,我使用此routerLink:

<a [routerLink]="['/app/dashboard']">DashBoard</a>

生成此URL:

  

http://localhost:54675/app/dashboard

该视图加载没有问题。

但是,如果我只是在浏览器中输入该URL并按回车,我会得到一个空白页面。控制台和源中没有任何内容是空的。

我使用默认的HTML5 locationStrategy - 而不是哈希(#)。

这适用于路由器弃用。

我无法弄清楚我可能做错了什么,因为其他一切都在运作。

当我导航到填充URL时,我注意到控制台中出现404错误。这是因为服务器上的任何内容都不匹配此URL,但它需要加载应用程序然后路由到该URL。

以下是我的路线档案: app.routes.ts:

export const routes: RouterConfig = ([
    { path: '', component: SplashComponent },
    { path: 'login', component: SplashComponent },
    ...MainRoutes
]);
export const APP_ROUTER_PROVIDERS = [
    provideRouter(routes)
];

main.routes.ts

export const MainRoutes: RouterConfig = [
    {
        path: 'app',
        component: MainLayoutComponent,
        children: [
                { path: 'dashboard', component: DashboardComponent},
                { path: '', component: DashboardComponent },
                { path: 'user', component: AccountEditComponent },
                { path: 'admin', component: ManageComponent }
            ]
    }
];

1 个答案:

答案 0 :(得分:1)

我的Angular2应用程序托管在DotNet Core应用程序中。我必须将其配置为在返回404的URL上重定向到index.html。我跟着这篇文章:

http://asp.net-hacker.rocks/2016/04/04/aspnetcore-and-angular2-part1.html