我有这个路由设置:
const SONGS_ROUTES = [
{
path: "songs",
children: [
// ...
{
path: "edit/:id",
component: PerformancesComponent, // CHILD ROUTE
},
{
path: "",
component: PerformancesComponent,
},
],
},
];
const routes: Routes = [
{
path: "",
component: ConcertsComponent,
children: [
{
path: "edit/:friendlyUrl",
component: ConcertEditComponent, // PARENT route
children: SONGS_ROUTES,
},
],
},
];
我需要能够friendlyUrl
在树中的每个组件中使用 ngrx 选择器。所以我定义如下:
export const routerFeatureKey = "router";
export const selectRouterState = createFeatureSelector<
fromRouter.RouterReducerState
>(routerFeatureKey);
export const {
selectCurrentRoute, // select the current route
selectQueryParams, // select the current route query params
selectQueryParam, // factory function to select a query param
selectRouteParams, // select the current route params
selectRouteParam, // factory function to select a route param
selectRouteData, // select the current route data
selectUrl, // select the current url
} = fromRouter.getSelectors(selectRouterState);
export const getSelectedConcertFriendlyUrl = selectRouteParam("friendlyUrl");
它确实在“父”级别组件(路由)上工作。这意味着当用户转到edit/some-concert
选择器时会返回some-concert。但是对于/edit/some-concert/edit/songs/1
(在子组件中)它返回undefined
. 我不知道为什么。
我都试过了routerState: RouterState.Minimal
和routerState: RouterState.Full
。结果相同。
我可以尝试哪些新事物?