sammyjs optional parameters

后端 未结 4 1435
-上瘾入骨i
-上瘾入骨i 2021-01-02 23:27

Just wondering if there is anyway to specify a parameter as optional in a sammy js route.

I\'ve seen somewhere that you can use

route/:foo/?:bar
         


        
4条回答
  •  不知归路
    2021-01-02 23:46

    this.get("#/:param1(/:param2)?", function (context) {
        var result = this.params['splat'];
    });
    

    The only issue with this approach is param2 will start with a '/', but this can be removed easily.

    '#/go' => {result[0]: 'go', result[1]: ''}
    '#/go/here' => {result[0]: 'go', result[1]: '/here'}
    

提交回复
热议问题