本文整理汇总了TypeScript中mithril.route.set方法的典型用法代码示例。如果您正苦于以下问题:TypeScript route.set方法的具体用法?TypeScript route.set怎么用?TypeScript route.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mithril.route
的用法示例。
在下文中一共展示了route.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: resolve
.catch(err => {
if (!window.username && err.message.indexOf("authorized") >= 0) {
notifications.push("error", err.message);
m.route.set("/login", { continue: requestedPath });
}
state = { error: err.message };
resolve();
});
示例2:
onmatch: () => {
for (const page of adminPages) {
if (window.authorizer.hasAccess(page, 2)) {
m.route.set(`/admin/${page}`);
return null;
}
}
return null;
}
示例3: setTimeout
setTimeout(() => {
m.route.set("/b");
setTimeout(() => {
console.assert(m.route.get() === "/b");
}, FRAME_BUDGET);
}, FRAME_BUDGET);
示例4: view
// http://mithril.js.org/route.html#wrapping-a-layout-component
////////////////////////////////////////////////////////////////////////////////
{
const Home = {
view() {
return "Welcome";
}
};
const state = {
term: "",
search() {
// save the state for this route
// this is equivalent to `history.replaceState({term: state.term}, null, location.href)`
m.route.set(m.route.get(), null, { replace: true, state: { term: state.term } });
// navigate away
location.href = "https://google.com/?q=" + state.term;
}
};
const Form: m.Comp<{term: string}, {}> = {
oninit(vnode) {
state.term = vnode.attrs.term || ""; // populated from the `history.state` property if the user presses the back button
},
view() {
return m("form", [
m("input[placeholder='Search']", { oninput: m.withAttr("value", v => { state.term = v; }), value: state.term }),
m("button", { onclick: state.search }, "Search")
]);