Angular 7 在 url 中传递参数,将数据作为 url 中的参数从后端发送到 Angular 前端

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

我使用 Angular 7 作为前端,django 作为后端,我将 url 中的购物车 id 作为参数传递(例如:http://localhost:4200/cartModule/cartId)。 早些时候,我将 id 作为查询参数发送(例如:http://localhost:4200/cartModule/?id=cartId)。

当我发送 http://localhost:4200/cartModule/cartId 时,它会重定向到 http://localhost:4200/auth/carts/cart 。

在我的lazy-load.module.ts中

const routes: Routes = [   
{path: 'auth', loadChildren: '../auth/auth.module#AuthModule'},
{path: '**', redirectTo: 'auth/carts/cart'},

]

在我的 auth.module.ts 中

export const appRoutes: Routes = [{ 
  path:'',component: AuthComponent, children: [
    {path: 'carts', loadChildren: '../carts/cart.module#CartsModule'},
  ]}

]

在我的 cart.module.ts 中,来自 './cart.router' 的 { CartRouterModule };被导入到模块中,

const materialWidgetRoutes: Routes = [
{ path: 'cart', component: CartComponent ,data: { animation: 'cart' }},

上面是 cart.router.ts

我发现这些文件相互关联并负责路线。 我希望 http://localhost:4200/cartModule/cartId 重定向到 http://localhost:4200/auth/carts/cart/cartId ,以便它在 url 中也包含购物车的 id ,它不应该重定向到 http ://localhost:4200/auth/carts/cart ,删除 /cartId

请帮忙。 谢谢

angular routes angular-routing angular-router
© www.soinside.com 2019 - 2024. All rights reserved.