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

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

问题描述

是否有可能让路由器命名的出口被激活一次,然后永远不会被破坏,无论在主要出口中导航什么路线?

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.

要求命名的出口不应以任何负面方式影响用户体验,例如通过向 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.

推荐答案

Router 需要有关命名插座的信息,因此很有可能实现您自己的 UrlSerializer 会有所帮助.

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

想法很简单,反序列化过程应该知道具有静态命名出口的路由,并产生包含命名出口的 UrlTree,即对于 /login url 应该产生相同的 UrlTree 作为默认序列化程序将为 url /login(popup:compose) 生成.在序列化期间,静态命名插座参数不应包含在生成的 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天全站免登陆