react-router#generatePath JavaScript Examples
The following examples show how to use
react-router#generatePath.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.js From frontend-app-discussions with GNU Affero General Public License v3.0 | 6 votes |
discussionsPath = (path, params) => {
const pathname = generatePath(path, params);
return (location) => ({ ...location, pathname });
}
Example #2
Source File: PostsView.test.jsx From frontend-app-discussions with GNU Affero General Public License v3.0 | 5 votes |
async function renderComponent({
postId, topicId, category, myPosts,
} = { myPosts: false }) {
let path = generatePath(Routes.POSTS.ALL_POSTS, { courseId });
let page;
if (postId) {
path = generatePath(Routes.POSTS.ALL_POSTS, { courseId, postId });
page = 'posts';
} else if (topicId) {
path = generatePath(Routes.POSTS.PATH, { courseId, topicId });
page = 'posts';
} else if (category) {
path = generatePath(Routes.TOPICS.CATEGORY, { courseId, category });
page = 'category';
} else if (myPosts) {
path = generatePath(Routes.POSTS.MY_POSTS, { courseId });
page = 'my-posts';
}
await render(
<IntlProvider locale="en">
<AppProvider store={store}>
<MemoryRouter initialEntries={[path]}>
<DiscussionContext.Provider value={{
courseId,
postId,
topicId,
category,
page,
}}
>
<Switch>
<Route path={Routes.POSTS.MY_POSTS}>
<PostsView />
</Route>
<Route
path={[Routes.POSTS.PATH, Routes.POSTS.ALL_POSTS, Routes.TOPICS.CATEGORY]}
component={PostsView}
/>
</Switch>
</DiscussionContext.Provider>
</MemoryRouter>
</AppProvider>
</IntlProvider>,
);
}