Z
Z
zlodiak2020-06-15 21:14:30
backbone.js
zlodiak, 2020-06-15 21:14:30

Why is the view not reloading?

Wrote the simplest website, which consists of three pages. Each page has its own view, the router draws the corresponding view depending on the state of the address bar.

router:

const Router = Backbone.Router.extend({
  routes: {
    '':       'page1',
    'page1':  'page1',
    'page2':  'page2',
    'page3':  'page3',
  },
  page1() {
    app.showView(pageView1);
  },
  page2() {
    app.showView(pageView2);
  },
  page3() {
    app.showView(pageView3);
  }
});
const router = new Router()


Representation:
const PageView = View.extend();
const pageView1 = new PageView({
  template: _.template('<h1>qwerty <%= header %></h1>'),
  model: pageModel1,
});
const pageView2 = new PageView({
  template: _.template('<h1>qwerty <%= header %></h1>'),
  model: pageModel2,
});
const pageView3 = new PageView({
  template: _.template('<h1>qwerty <%= header %></h1>'),
  model: pageModel3,
});


The problem is that after the user clicks the navigation links 5-7 times, the following error message is displayed in the console:
Uncaught constructor {name: "RegionError", message: "View (cid: "view5") has already been destroyed and cannot be used.", url: " marionettejs.com/docs/v4.1.2/marionette.region.htm. .. ", stack: "RegionError: View (cid: "view5") has already been …x/libs/ backbone.js/1.4.0/backbone-min.js:1:23438 )"}


I looked at the documentation on the link in the message, it says that the error can appear if the region has already shown a view or has been destroyed:
An error will be thrown if the view is falsy or destroyed.
An error will be thrown if the view is already shown in a Region


But neither one nor the other happens in my code: LIVE DEMO

Please help me get rid of this error message.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question