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 8434375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:38:19+00:00 2026-06-10T06:38:19+00:00

I’m trying to simplify routes. What I have now still requires a reference inside

  • 0

I’m trying to simplify routes. What I have now still requires a reference inside the class that extends router, but since I’m using eval to instantiate references, every route method is the same.

Currently, inside my app:

ROUTES =
  'action1/:page': 'action1'
  'action2/:page': 'action2'
  '*path': 'default' # Default routes to action1

# Start Backbone history.
App.Router = new Routes(
  routes: ROUTES
)
App.Router.setDefaultRoute 'action1'
Backbone.history.start()

And the Router class:

class window.Routes extends Backbone.Marionette.AppRouter

  constructor: (options) ->

    @on 'all', @storeRoute
    @history = []
    super options

  @trace initialize: () ->

    debug.info 'Routes: ' + JSON.stringify @routes

  @trace setDefaultRoute: (route) ->

    App.Data.defaultRoute = route

  @trace getDefaultRoute: () ->

    App.Data.defaultRoute

  @trace storeRoute: () ->

    @history.push Backbone.history.fragment

  @trace getPrevious: () ->

    if @history.length > 1
      @history[@history.length - 1] 

  @trace getPreviousRoute: () ->

    @getPrevious().split('/')[0]

  @trace getPreviousPage: () ->

    @getPrevious().split('/')[1]

  @trace getFormattedWindowHash: () ->

    hash = window.location.hash
    hash = hash.substring(1, hash.length) 

    hash

  @trace getCurrentRoute: () ->

    current = @getFormattedWindowHash().split('/')[0]

    # Allow us to not specify 'route = <route>' inside every routing method.
    if !current
      current = @getDefaultRoute()
    else
      current = current

    current = current.charAt(0).toUpperCase() + current.slice(1)    

  @trace getCurrentPage: () ->

    @getFormattedWindowHash().split('/')[1]

  # Everytime a page is loaded, default data is cleared by instantiating new 
  # Views, Events, UI, State, and Error classes.
  @trace setupPage: (page) ->

    route = @getCurrentRoute()

    debug.info 'current route: ' + route

    event = 'App.Pages.Events.' + route + ' = new App.Events.' + route + '()'
    debug.info 'eval event: ' + event

    eval event

    # The magic which routes to the page.
    goTo = 'App.Pages.Events.' + route + '.router(parseInt(' + page + '))'
    debug.info 'goTo: ' + goTo

    eval goTo

  # Place routing actions below.

  @trace action1: (page) ->

    @setupPage page

  @trace action2: (page) ->

    @setupPage page

  # Default route.
  @trace default: () ->

    # TODO make this settable?
    @action1 1

What I want to do is be able to remove these 3 methods:

 @trace action1: (page) ->

    @setupPage page

  @trace action2: (page) ->

    @setupPage page

  # Default route.
  @trace default: () ->

    # TODO make this settable?
    @action1 1

How can I accomplish this?

Running: http://franklovecchio-playback.herokuapp.com/?log=true

Full code: https://github.com/franklovecchio/playback

  • 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-10T06:38:20+00:00Added an answer on June 10, 2026 at 6:38 am

    You can get away with two route handlers:

    ROUTES =
      'action1/:page': 'page'
      'action2/:page': 'page'
      '*path': 'def'
    

    and then:

    page: (page) ->
      @setupPage(parseInt(page, 10))
    def: ->
      @setupPage(1)
    

    The splat route (*path) will send the matched part of the route to the handler so you can’t use just one route handler without attempting to interpret what the splat matches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.