一次激活的路由器命名插座 [英] Router named outlets that are activated once

查看:62
本文介绍了一次激活的路由器命名插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使路由器命名的插座被激活一次,然后再销毁,无论在主插座中导航的路线是什么?

Is it possible to have router named outlets that are activated once and then never destroyed, no matter what route is navigated in primary outlet?

目的是使组件保留在页面上(例如,侧栏),但在其初始加载时获得路由的好处-例如警卫(解析器)和延迟加载.

The intention is to have components that persist on page (for instance, sidebar) but get the benefits of routing on their initial load - such as guards (resolvers) and lazy loading.

要求是命名出口不应以任何负面方式影响UX,例如通过在SPA URL中引入垃圾后缀,例如(outletName:routeName),也不应意外停用它们.如果有一种方法可以在初始激活后将其与路由器分离,那将是适当的.

The requirement is that named outlets shouldn't affect UX in any negative way, for example by introducing garbage suffixes to SPA URL, e.g. (outletName:routeName), they also shouldn't be accidentally deactivated. If there's a way to detach them from router after initial activation, it would be appropriate.

skipLocationChange选项不能用于此目的.在此示例/login(popup:compose) URL是在依次导航ContactLogin路线时出现的.

skipLocationChange option cannot be used for this purpose. In this example /login(popup:compose) URL appears when Contact and Login routes are sequentially navigated.

推荐答案

路由器需要有关命名插座的信息,因此实施自己的UrlSerializer很有可能会有所帮助.

Router needs information about named outlets, so there are good chances that implementing your own UrlSerializer will help.

想法很简单,反序列化过程应注意具有静态命名出口并产生UrlTree且包含命名出口的路由,即对于/login url应产生与默认序列化程序将为url UrlTree >.在序列化期间,静态的命名出口参数不应包含在结果url中.

Idea is simple, deserialization process should be aware of routes which have static named outlets and produce UrlTree which contains named outlets i.e. for /login url should produce the same UrlTree as default serializer will produce for url /login(popup:compose). During serialization static named outlet parameters should not be included into resulting url.

这篇关于一次激活的路由器命名插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆