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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:49:04+00:00 2026-06-18T06:49:04+00:00

I have a problem with my router not redirecting when i call navigate. Im

  • 0

I have a problem with my router not redirecting when i call navigate.

Im running a Rails setup with the ‘backbone-on-rails’ gem.

The problem seems to be related to how the app is initialised.

App

window.App =
  Models: {}
  Collections: {}
  Views: {}
  Routers: {}
  initialize: ->
    new App.Routers.Main()
    Backbone.history.start({pushState: true})

$ ->
  App.initialize()

Router

class App.Routers.Main extends Backbone.Router

  routes:
    '': 'index'
    'login': 'login'


  initialize: ->
    # Check login status
    @check_login_status()


  initialize_layout: ->
    # Default layout template
    layout        = new App.Views.Layout
    $('#main').html( layout.render().el )

    # Navigation template
    navigation  = new App.Views.Navigation(user: @current_user)
    $('#main nav[role="top"]').html( navigation.render().el )

    # Return this
    this


  index: ->
    @initialize_layout() unless @current_user.get('company_id') is null
    this


  login: ->
    layout        = new App.Views.Layout
    $('#main').html( layout.render().el )

    login       = new App.Views.Login
    $('#main .container-fluid').html(login.render().el)


  check_login_status: ->
    @current_user = new App.Models.CurrentUser
    @current_user.fetch({
      async: false
      success: (data, status, xhr) ->

        # If no user is logged in, and we arent on the login page, redirect to it
        if data.get('company_id') is null and window.location.pathname isnt '/login'
          # Navigate to login page
          window.location.href = '/login'

    })

In my router i have an initialise function that checks wether or not the user is logged in. I console.log a simple status to easily verify it, and indeed it logs out ‘not logged in’.

Despite that, the navigate doesnt redirect to /login.

If i start backbone history before i start the router, then the navigate part works, but when i refresh the page (cmd+r) then the router doesn’t run the index method.

  • 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-18T06:49:05+00:00Added an answer on June 18, 2026 at 6:49 am

    The reason the navigation to /login doesn’t trigger the route login is the leading forward slash. If you leave out the forward slash, it should work:

    self.navigate('login', {trigger: true})
    

    Forward slash -prefixed URL means that the route should be found at the domain’s root, i.e. domain.com/login. To maintain the flexibility to run your application in a URL that’s not in the application’s root, say, domain.com/en/login, you should prefer the relative URL format.

    You also say:

    start backbone history before i start the router, then the navigate part works

    This is probably not a good idea. I don’t know exactly how it “works”, but the Backbone documentation is quite clear on this topic:

    During page load, after your application has finished creating all of its routers, be sure to call Backbone.history.start(), or Backbone.history.start({pushState: true}) to route the initial URL.

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

Sidebar

Related Questions

I have a problem with a backbone.js namespacing app demo, i'm trying to display
When defining a resources in routes.rb in Rails, I have the following problem: My
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have a problem with a new app I am writing. The app connects
I have been working on a project that uses Backbone.js router and all data
I have a bit of problem with new router. I would like to have
I have problem in my heroku app, I am trying to send email using
I have the following setup: Dedicated server --> Internet --> Modem (telenet) --> Router
I have a Firebase app that works perfectly on localhost, but does not work
I tried to use backbone with a pushstate: $(document).ready(function(){ var App = Backbone.Router.extend({ routes:

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.