Manually register component at slug #4825
-
Is it possible to register a component at a specific slug manually, instead of having to specify it via the The usecase is that I want to group redirects from old pages to new pages in a single file, to prevent cluttering up my hierarchy with page files containing a single redirect. I'm planning to implement the actual redirect using the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You'd rather configure redirects on the server, using your hosting provider configuration, cf what we do on the Docusaurus site itself using Netlify Using client-side redirects like
This is not documented very well but this is what our plugins lifecycle allows (quite similarly to Gatsby's createPage) https://docusaurus.io/docs/lifecycle-apis#async-contentloadedcontent-actions export default function myRedirectRoutesPlugin(context, options) {
return {
name: 'myRedirectRoutesPlugin',
async contentLoaded({content, actions}) {
actions.addRoute({
path: '/myOldRoute',
exact: true,
component: '@site/src/components/MyCustomRedirectComponent.js',
});
actions.addRoute({
path: '/myOldRoute2',
exact: true,
component: '@site/src/components/MyCustomRedirectComponent.js',
});
},
};
} But I don't feel it's the ideal solution for your usecase |
Beta Was this translation helpful? Give feedback.
You'd rather configure redirects on the server, using your hosting provider configuration, cf what we do on the Docusaurus site itself using Netlify
_redirects
: https://github.com/facebook/docusaurus/blob/master/website/static/_redirectsUsing client-side redirects like
<Redirect>
is not really the recommended way to redirect an app: the redirect is done very late, only once the React app has been mounted/hydrated on the client. Eventually, using our client redirects plugin will be better than<Redirect>
because it creates simple html files, not requiring hydrating React.