123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- export default async function (to, from) {
-
- const { $webUrl, $CwebUrl } = useNuxtApp();
- if(getRouteWhiteList(to.path)){
-
- }else{
-
-
-
- let parts = parseRoute(to.path)
-
- const responseRoute = await $fetch($webUrl + '/web/checkWebsiteRoute', {
- headers: {
- 'Content-Type': 'application/json',
- 'Userurl': $CwebUrl,
- 'Origin': $CwebUrl
- },
- query: parts
- })
-
- if(responseRoute.code == 200){
-
- }else{
- return navigateTo('/404')
- }
- }
- }
- function parseRoute(url) {
- const parts = url.split('/').filter(Boolean);
- const lastPart = parts[parts.length - 1];
-
-
- const idMatch = lastPart.match(/^(\d+)\.html$/);
- const id = idMatch ? idMatch[1] : undefined;
-
-
- const isSpecialRoute = idMatch || lastPart === "index.html" || lastPart.startsWith("list-");
- if (isSpecialRoute) {
- parts.pop();
- }
-
- let all_route, last_route, other_route;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- all_route = parts.join('/');
- last_route = parts.length > 0 ? parts[parts.length - 1] : null;
- other_route = parts[0]
-
- const result = {
- all_route,
- last_route,
- other_route,
- };
- if (id !== undefined) {
- result.id = id;
- }
- return result;
- }
- function getRouteWhiteList(path){
- if(path=='/'||path=='/404'){
- console.log('该路由允许访问!')
-
- return true
- }else{
-
- const parts = path.split('/').filter(Boolean);
-
- let whiteList = [
-
-
-
-
-
-
- ]
- if(whiteList.includes(parts[0])){
- console.log('该路由允许访问!!')
- return true
- }else{
- return false
- }
- }
- }
|