Backbone.js route optional parameter

前端 未结 4 389
生来不讨喜
生来不讨喜 2021-02-01 01:51

Is it possible to have optional parameters in a Backbone.js route?

e.g this:

routes:
  \"search/[:query]\": \"searchIndex\"

instead of:

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 02:39

    What about using the *splat:

    routes router.routes

    The routes hash maps URLs with parameters to functions on your router, similar to the View's events hash. Routes can contain parameter parts, :param, which match a single URL component between slashes; and splat parts *splat, which can match any number of URL components.

    For example, a route of "search/:query/p:page" will match a fragment of #search/obama/p2, passing "obama" and "2" to the action. A route of "file/*path" will match #file/nested/folder/file.txt, passing "nested/folder/file.txt" to the action.

提交回复
热议问题