createUrlTreeFromSnapshot
Создает UrlTree относительно ActivatedRouteSnapshot.
API
function createUrlTreeFromSnapshot( relativeTo: ActivatedRouteSnapshot, commands: readonly any[], queryParams?: Params | null, fragment?: string | null, urlSerializer?: DefaultUrlSerializer, ): UrlTree;
readonly any[]Массив фрагментов URL, из которых строится новое дерево URL. Если путь статический, можно указать строку URL. Для динамического пути передайте массив сегментов пути, за которым следуют параметры для каждого сегмента. Фрагменты применяются к указанному в параметре relativeTo значению.
DefaultUrlSerializerUrlSerializer, используемый для обработки нормализации параметров запроса. Если для разбора и сериализации значений параметров запроса из объектов и обратно настроен пользовательский UrlSerializer вашего приложения, следует указать его.
UrlTree
Примечания по использованию
// create /team/33/user/11
createUrlTreeFromSnapshot(snapshot, ['/team', 33, 'user', 11]);
// create /team/33;expand=true/user/11
createUrlTreeFromSnapshot(snapshot, ['/team', 33, {expand: true}, 'user', 11]);
// you can collapse static segments like this (this works only with the first passed-in value):
createUrlTreeFromSnapshot(snapshot, ['/team/33/user', userId]);
// If the first segment can contain slashes, and you do not want the router to split it,
// you can do the following:
createUrlTreeFromSnapshot(snapshot, [{segmentPath: '/one/two'}]);
// create /team/33/(user/11//right:chat)
createUrlTreeFromSnapshot(snapshot, ['/team', 33, {outlets: {primary: 'user/11', right:
'chat'}}], null, null);
// remove the right secondary node
createUrlTreeFromSnapshot(snapshot, ['/team', 33, {outlets: {primary: 'user/11', right: null}}]);
// For the examples below, assume the current URL is for the `/team/33/user/11` and the
`ActivatedRouteSnapshot` points to `user/11`:
// navigate to /team/33/user/11/details
createUrlTreeFromSnapshot(snapshot, ['details']);
// navigate to /team/33/user/22
createUrlTreeFromSnapshot(snapshot, ['../22']);
// navigate to /team/44/user/22
createUrlTreeFromSnapshot(snapshot, ['../../team/44/user/22']);
Super-powered by Google ©2010–2025.
Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0.
https://angular.dev/api/router/createUrlTreeFromSnapshot