当从应用程序中请求URL时,带参数的角度路由不起作用

问题描述 投票:0回答:1

我的Angular路由有问题,如果从应用程序中请求带有参数的URL,应用程序将失败。

http://localhost:4200/clients如果您从应用程序导航到该路线或只是在地址栏中输入该路线,则该路线有效。

http://localhost:4200/clients/20如果您从应用程序导航到此路线,并且如果在地址栏中输入则无效,则此路线有效。

注意:在控制台中,它从二级路由请求css和javascript文件(http://localhost:4200/clients/assets/vendor/jquery/jquery.js而不是http://localhost:4200/assets/vendor/jquery/jquery.js

有帮助吗?

angular url-routing angular-routing
1个回答
0
投票

通过启用路由中的哈希来完成修复。

在app.module.ts中

RouterModule.forRoot(
      [
        { path: 'Home', component: HomeComponent },
        { path: 'ImportOperations', component: ImportOperationComponent },
        { path: 'ImportData/:Id', component: ImportRawDataComponent },
        { path: 'rules/:Id', component: RulesComponent },
        { path: 'newrule', component: RulesComponent },
        { path: 'rules', component: RulesListComponent },
        { path: 'search', component: SearchComponent },        
        { path: 'editresult/:Id', component: EditSearchComponent }
      ]
      ,{useHash: true}), 
© www.soinside.com 2019 - 2024. All rights reserved.