var AppRouter = Backbone.Router.extend({ routes: { "": "home", "products": "showProducts", "products/:id": "showProductDetails", "*path": "notFound" }, home: function() { console.log("Home page"); }, showProducts: function() { console.log("List of products"); }, showProductDetails: function(id) { console.log("Product details for ID: " + id); }, notFound: function(path) { console.log("Invalid URL: " + path); } }); var appRouter = new AppRouter(); Backbone.history.start();
appRouter.navigate("products/123", { trigger: true });This example demonstrates how to programmatically navigate to a specified route using the `navigate` method of Backbone Router. The first parameter is the URL fragment to navigate to, and the second parameter is an options object. The `trigger` option is set to `true` to trigger the associated function for the route. Package library: Backbone.js