Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8244473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:51:44+00:00 2026-06-07T21:51:44+00:00

Regarding the new Ember.js routing system (described here ), if I understand correctly, views

  • 0

Regarding the new Ember.js routing system (described here), if I understand correctly, views are destroyed when you exit a route.

Is there any way to bypass destruction of views upon exiting a route, so that the state of the view is preserved when the user re-enters the route?


Update: Looks like, views are not destroyed unless the outlet view is being replaced in the new route. For e.g., if you are in stateA with ViewA in some {{outlet master}} and you go to stateB with ViewB in {{outlet master}}, then ViewB will replace ViewA. A way around this is to define multiple outlets when you need to preserve views, e.g., {{outlet master1}}, {{outlet master2}}, …

A nice feature would be the ability to pass an array of views to the outlet. And also be able to choose whether views will be destroyed or just become hidden, upon exiting a route.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:51:46+00:00Added an answer on June 7, 2026 at 9:51 pm

    I have since figure out how to modify the routing system, so that views inserted into outlets are not destroyed. First I override the Handlebars outlet helper, so that it loads an Ember.OutletView into {{outlet}}:

    Ember.Handlebars.registerHelper('outlet', function(property, options) {
      if (property && property.data && property.data.isRenderData) {
        options = property;
        property = 'view';
      }
    
      options.hash.currentViewBinding = "controller." + property;
    
      return Ember.Handlebars.helpers.view.call(this, Ember.OutletView, options);
    });
    

    Where Ember.OutletView extends Ember.ContainerView as follows:

    Ember.OutletView = Ember.ContainerView.extend({
        childViews: [],
    
        _currentViewWillChange: Ember.beforeObserver( function() {
            var childViews = this.get('childViews');
    
                // Instead of removing currentView, just hide all childViews
                childViews.setEach('isVisible', false);
    
        }, 'currentView'),
    
        _currentViewDidChange: Ember.observer( function() {
            var childViews = this.get('childViews'),
                currentView = this.get('currentView');
    
            if (currentView) {
                // Check if currentView is already within childViews array
                // TODO: test
                var alreadyPresent = childViews.find( function(child) {
                   if (Ember.View.isEqual(currentView, child, [])) {          
                       return true;
                   } 
                });
    
                if (!!alreadyPresent) {
                    alreadyPresent.set('isVisible', true);
                } else {
                    childViews.pushObject(currentView);
                }
            }
        }, 'currentView')
    
    });
    

    Basically we override _currentViewWillChange() and just hide all childViews instead of removing the currentView. Then in _currentViewDidChange() we check if the currentView is already inside childViews and act accordingly. The Ember.View.isEqual is a modified version of Underscore isEqual:

    Ember.View.reopenClass({ 
        isEqual: function(a, b, stack) {
            // Identical objects are equal. `0 === -0`, but they aren't identical.
            // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
            if (a === b) return a !== 0 || 1 / a == 1 / b;
            // A strict comparison is necessary because `null == undefined`.
            if (a == null || b == null) return a === b;
            // Unwrap any wrapped objects.
            if (a._chain) a = a._wrapped;
            if (b._chain) b = b._wrapped;
            // Compare `[[Class]]` names.
            var className = toString.call(a);
            if (className != toString.call(b)) return false;
    
            if (typeof a != 'object' || typeof b != 'object') return false;
            // Assume equality for cyclic structures. The algorithm for detecting cyclic
            // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
            var length = stack.length;
            while (length--) {
                // Linear search. Performance is inversely proportional to the number of
                // unique nested structures.
                if (stack[length] == a) return true;
            }
            // Add the first object to the stack of traversed objects.
            stack.push(a);
            var size = 0, result = true;
            // Recursively compare objects and arrays.
            if (className == '[object Array]') {
                // Compare array lengths to determine if a deep comparison is necessary.
                size = a.length;
                result = size == b.length;
                if (result) {
                    // Deep compare the contents, ignoring non-numeric properties.
                    while (size--) {
                        // Ensure commutative equality for sparse arrays.
                        if (!(result = size in a == size in b && this.isEqual(a[size], b[size], stack))) break;
                    }
                }
            } else {
                // Objects with different constructors are not equivalent.
                if (a.get('constructor').toString() != b.get('constructor').toString()) {
                    return false;
                }
    
                // Deep compare objects.
                for (var key in a) {
                    if (a.hasOwnProperty(key)) {
                        // Count the expected number of properties.
                        size++;
                        // Deep compare each member.
                        if ( !(result = b.hasOwnProperty(key) )) break;
                    }
                }
            }
            // Remove the first object from the stack of traversed objects.
            stack.pop();
            return result;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(I am new to Schema validation) Regarding the following method, System.Xml.Schema.Extensions.Validate( ByVal source As
I'm new to SharePoint and have a general question regarding list comparison. Currently, there
I'm new to django and had a question regarding organizing views. manage.py startapp creates
I am new to Android development and I have a question regarding custom views
Regarding the new ScriptDb service; from the frequently asked questions section: What are the
I have a question regarding the new iPad 3 and iBooks. I'm trying to
Am new to development.I got an error regarding the Expected a Type error.In two
I'm new to version control and I have a question regarding branching. I have
I am new to chef and I have a question regarding the following. I
I am somewhat new to LINQ and have a quick question regarding deleting. Say,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.