[docs] Add ability to redirect based on input path. (#23851)
This commit is contained in:
		
							parent
							
								
									41dbb4c86c
								
							
						
					
					
						commit
						282253a7e0
					
				
					 2 changed files with 87 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -2,11 +2,22 @@
 | 
			
		|||
import DefaultTheme from 'vitepress/theme'
 | 
			
		||||
import { useRouter } from 'vitepress'
 | 
			
		||||
import { onBeforeMount } from 'vue';
 | 
			
		||||
import aliases from "../../../../docs/_aliases.json";
 | 
			
		||||
 | 
			
		||||
const router = useRouter()
 | 
			
		||||
onBeforeMount(async () => {
 | 
			
		||||
    if (window.location.href.includes('/#/')) {
 | 
			
		||||
        const newUrl = window.location.href.replace(/\/#\//, '/').replace(/\?id=/, '#');
 | 
			
		||||
    // Convert from docsify-style to vitepress-style URLs
 | 
			
		||||
    let newUrl = window.location.href.replace(/\/#\//, '/').replace(/\?id=/, '#');
 | 
			
		||||
 | 
			
		||||
    // Convert any aliases
 | 
			
		||||
    let testUrl = new URL(newUrl);
 | 
			
		||||
    while (testUrl.pathname in aliases) {
 | 
			
		||||
        testUrl.pathname = aliases[testUrl.pathname];
 | 
			
		||||
    }
 | 
			
		||||
    newUrl = testUrl.toString();
 | 
			
		||||
 | 
			
		||||
    // Redirect if required
 | 
			
		||||
    if (newUrl != window.location.href) {
 | 
			
		||||
        window.history.replaceState({}, '', newUrl);
 | 
			
		||||
        await router.go(newUrl);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue