我正在创建一个应用程序,它接收一组数据并将其显示在页面上
由于我想按位置,日期,价格和评级来过滤,我必须创建下一条路线:
":location": "func1"
":location/dates/:dates": "func2"
":location/dates/:dates/prices/:prices": "func3"
":location/dates/:dates/prices/:prices/ratings/:ratings": "func4"
":location/dates/:dates/ratings/:ratings": "func5"
":location/prices/:prices": "func6"
":location/prices/:prices/ratings/:ratings": "func7"
":location/ratings/:ratings": "func8"
你可以看到这里有重复项,我会避免它,并能够捕获网址中的所有过滤器
如何以更好的方式实现,所以我不需要根据所有可能性复制路线?
答案 0 :(得分:1)
您可以使用可选参数将其简化为一条路线:
":location(/dates/:dates)(/prices/:prices)(/ratings/:ratings)": "func1"