Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. routes: {
  2. 'lions': 'animalsRoute',
  3. 'animals': 'animalsRoute'
  4. },
  5. animalsRoute: function() {
  6. this.navigate("#/animals", { replace: true });
  7. // or using the global history object:
  8. // Backbone.history.navigate("#/animals", { replace: true });
  9. }
  10.  
  11. routes: {
  12. 'lions': 'lionsRoute',
  13. 'tigers': 'tigersRoute'
  14. },
  15. showGenericRoute: function() {
  16. this.navigate("#/animals", { replace: true });
  17. },
  18. tigersRoute: function() {
  19. this.showGenericRoute();
  20. // handle the tigers route
  21. },
  22. lionsRoute: function() {
  23. this.showGenericRoute();
  24. // handle the lions route
  25. }
  26.  
  27. routes: {
  28. 'animals/:animal': 'animalsRoute',
  29. },
  30. animalsRoute: function(animal) {
  31. // removes the animal from the url.
  32. this.navigate("#/animals", { replace: true });
  33.  
  34. // use the chosen animal
  35. var view = new AnimalView({ type: animal });
  36. }
  37.  
  38. var Router = Backbone.Router.extend({
  39. routes: {
  40. 'animals': 'animalsRoute'
  41. },
  42. animalsRoute: function() {
  43. // handle the generic behavior.
  44. }
  45. });
  46.  
  47. var PussyRouter = Backbone.Router.extend({
  48. routes: {
  49. 'lions': 'lionsRoute'
  50. // ...
  51. },
  52. lionsRoute: function() {
  53. // handle lions, then redirect
  54. this.navigate("#/animals", { trigger: true, replace: true });
  55. }
  56. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement