2016-06-07 95 views
0

我的網址在我的項目是這樣的:https://localhost:3000/groups/KhHB9TwzZxiddgJND/event自定義URL流星

我想somethink這樣的:https://localhost:3000/groups/groupName/event

我該怎麼辦呢?我使用流星1.3火焰,流路由器路由

回答

0

你只定義您的路線,並使用name變量,而不是一個id

FlowRouter.route('/groups/:name/event', {}); 

再後來,當你想設置的數據上下文您的模板,你會做這樣的事情:

let groupName = FlowRouter.getParam("name"); 
const group = Groups.findOne({ name: groupName }); 

_id是不是在一個特殊的路線,路線參數是隻是一些你最終將通過進行搜索。 _id的好處是保證了它的獨特性。如果您按名稱搜索,那麼除非您確實需要列表,否則您可能必須在模型中強制執行唯一性。

+0

它的工作原理,但我怎麼能在URL中獲得''?我得到這個:'http:// localhost:3000/groups/My%40Group/event'並且想要這個:'http:// localhost:3000/groups/My_Group/event'。 URL中沒有符號代碼。有任何想法嗎? –

+0

也許嘗試decodeURI? https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/decodeURI –