简体   繁体   English

在任何路线的顶部路由模态

[英]Routing a modal on top of any route

I'm currently trying to implement a requirement for a routable modal in my ember app. 我正在尝试在我的ember应用程序中实现可路由模式的要求。 The goal is to have a tabbed modal overlay where each tab has it's own URL (eg, /settings , /settings/profile , or /settings/billing ) but still displayed over whatever route is currently in the background. 目标是使用选项卡式模式叠加,其中每个选项卡都有自己的URL(例如, /settings/settings/profile/settings/billing ),但仍然显示当前后台的任何路径上。

A live example might be twitter.com 's direct messages modal, but having it so that opening the modal (and clicking links inside the modal) update the app's URL. 一个现实的例子可能是twitter.com的直接消息模式,但是让它打开模态(并点击模态内的链接)更新应用程序的URL。

The main wall I've hit in trying to implement this is that my outlets get disconnected upon exit of the 'top' route. 我试图实现这一点的主要障碍是我的网点在退出“顶部”路线后断开连接。 I've had some initial success with overriding Route#teardownViews but I'm worried about other side-effects. 我已经在覆盖Route#teardownViews取得了一些初步成功,但我担心其他副作用。

EDIT: For clarity, I do render the modal in a separate outlet: 编辑:为了清楚起见,我确实在单独的插座中渲染模态:

SettingsRoute = Ember.Route.extend

  renderTemplate: ->
    @render
      into: 'application'
      outlet: 'modal'

Might there be a better approach overall to take here? 可能会有一个更好的方法来采取这里?

This seems to work conceptually (I only tear down the 'main' route's views if I'm not transitioning to a messages or settings route (which I have defined as 'modal' routes)): 这似乎在概念上有效(如果我没有转换到消息或设置路径(我已经定义为'模态'路线),我只会拆除'主'路线的视图):

Ember.Route.reopen

  teardownViews: ->
    @_super() unless @controllerFor('application').get('currentTransition.targetName') == 'messages.index'

  actions:
    willTransition: (transition) ->
      controller = @controllerFor('application')

      controller.set('currentTransition', transition)

      transition.then ->
        controller.set('currentTransition', null)
      , ->
        controller.set('currentTransition', null)

Will post back if I make any other progress. 如果我做任何其他进展,将回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM