有没有办法处理递归未知的确切数量的路由器参数?
例如:
我们有产品类别,可以有子类别,子类别可以有自己的子类别等等。有几个主要条件:
/categories/{id}/items
,这将打开项目列表组件。/categories/{id}/{id}/.../{id}
,该级别应打开最后一个categoryId子类别列表组件。/categories/{id}/{id}/.../{id}/items
。检查和重定向的解决方案是使用路由器解析器。但是如何在路由模块中跟踪这些网址呢?
从我的角度来看,路线看起来应该是这样的:
{
path: '/categories/:id',
component: SubcategoriesListComponent
},
{
path: '/categories/:id/**/:id',
component: SubcategoriesListComponent,
},
{
path: '/categories/:id/**/:id/items',
component: CategoryItemsListComponent
}
是否有可能以这种方式实现它?
答案 0 :(得分:4)
无组件路由的可能解决方案: 在路线配置
export class SubcategoriesListComponent {
constructor(aroute: ActivatedRoute) {
aroute.url.subscribe((data) => {
console.log('params ', data); //contains all the segments so put logic here of determining what to do according to nesting depth
});
}
}
组件文件中的:
#include <stdio.h>
int main()
{
int vektor[100];
int i, madhesia;
/* Input size of array */
printf("Madhesia e vektorit: ");
scanf("%d", &madhesia);
/* Input array elements */
printf("\nElementet: ");
for (i = 0; i < madhesia; i++)
{
scanf("%d", &vektor[i]);
}
printf("\nno of elements:%d",madhesia);
printf("\n");
for (i = 0; i < madhesia; i++)
{
printf("%d", vektor[i]);
}
printf("\n");
i=0;
int ret = numero(vektor,madhesia,0,i);
printf("\nTotal negative elements in array = %d", ret);
return 0;
}
int numero(int array[],int size,int count,int j)
{
if (j<=size-1)
{
if(array[j]<0)
{
count++;
j++;
numero(array,size,count,j);
}
else
{
j++;
numero(array,size,count,j);
}
}
return count;
}
这是output example(我在我的项目ErrorComponent上测试过,所以不要混淆)