Skip to content

Add a default view for unmapped route #5

Description

@sebez

It could be useful to have a default view for unmapped route, using a default route.

The idea is to have an error page for not mapped routes. This way, the application informs the user that he clicked a dead link, instead of just silently updating the hash in the browser.

Default router :

var layout = require('../views/layout');

module.exports = Fmk.Helpers.Router.extend({
    routes: {
        '*path': 'defaultRoute'
    },
    defaultRoute: function () {
        var View = require('../views/technique/routeNotFound/routeNotFoundStatic');
        var model = new Backbone.Model({route: Backbone.history.fragment});
        var view = new View({model: model});
        layout.content.show(view);
    }
});

We use the *splat joker to select all unmapped routes.

Beware, if there is several routers, the default router must be the first one to be initialized (and not the last one as one might think).

//Dependencies.
var DefaultRouter = require('./defaultRouter');
var HomeRouter = require("./homeRouter");
var AffaireRouter = require('./affaireRouter');

/*Router instanciation.*/
module.exports = {
    routerList: [
        new DefaultRouter(),
        new HomeRouter(),
        new AffaireRouter()
    ]
};

The view simply displayed the unmapped route :

<div class="techError">
    <h4><i class="fa fa-exclamation-triangle"></i> Route inexistante : {{route}}</h4>
</div>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions