How to detect invalid route and trigger function in Backbone.Controller
- by tomodian
Is there any method to detect invalid (or undefined) route and trigger 404 page in Backbone.Controller?
I've defined routes in my Controller like this, but it didn't work.
class MyController extends Backbone.Controller
    routes:
        "method_a": "methodA"
        "method_b": "methodB"
        "*undefined": "show404Error"
    # when access to /#method_a
    methodA: ->
        console.log "this page exists"
    # when access to /#method_b
    methodB: ->
        console.log "this also exists"
    # when access to /#some_invalid_hash_fragment_for_malicious_attack
    show404Error: ->
        console.log "sorry, this page does not exist"