Uncaught TypeError: App.Routers.Maintenances.MyRouter is not a constructor

33 Views Asked by At

I am using backbone js as frontend in rails 7 application. In index.html file I have called backbone main file. code is coming in this file. But here I have initialise router file. In which getting error of Router is not a constructor.

In index.html.haml file


- content_for :javascript do
  - javascript_include_tag 'backbone/estimate_repair', defer: true, type: "module"

In app/javascript/backbone/estimate_repair.js

//= require ./templates
//= require ./templates/maintenances/estimate_repair
//= require ./models
//= require ./views

//= require ./views/maintenances/estimate_repair
//= require ./routers

window.App = {
  Models: {},
  Collections: {},
  Routers: {
    Maintenances: {}
  },
  Views: {},
  init: () => {
    new App.Routers.Maintenances.MyRouter();
    Backbone.history.start();
  }
};

In app/javascript/backbone/routers/maintenances/MyRouter.js.coffee

App.Routers.Maintenances ||= {}

class App.Routers.Maintenances.MyRouter extends Backbone.Router

initialize: (options = {}) ->
  @estimate_router_view = newApp.Views.Maintenances.EstimateRepair.MyView()

Some time errors differ i.e. 'App is not defined' and when I defined it as an empty hash it showed "Uncaught SyntaxError: Unexpected token '.' at App.Routers".

0

There are 0 best solutions below