-
Notifications
You must be signed in to change notification settings - Fork 0
/
routing.js
59 lines (50 loc) · 1.67 KB
/
routing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Add various helpers related to routing
*/
import defaultsDeep from 'lodash/defaultsDeep'
import { srcHasPath, requireOnce } from '@cloak-app/utils'
import { sortRoutes } from '@nuxt/utils'
import { nonEmpty } from '../helpers/array'
export default function() {
// Make the tower slug optional, so the root route will match. This also
// adds support for slashes within Tower URIs.
if (srcHasPath(this.options, 'pages/_tower.vue')) {
this.extendRoutes(routes => {
routes.find(route => route.name == 'tower').path = '/:tower*'
sortRoutes(routes)
})
}
// Add default anchor parser rules
defaultsDeep(this.options, { anchorParser: {
addBlankToExternal: true,
}})
// Manually set internalUrls values, can't use defaultsDeep for this, see
// https://github.com/BKWLD/cloak-utils/issues/3
if (!this.options.anchorParser?.internalUrls) {
this.options.anchorParser.internalUrls = nonEmpty([
// Local dev
/^https?:\/\/localhost:\d+/,
// Use current URL from Netify
(function() {
if (!process.env.URL) return
const url = process.env.URL.replace(/[\/\-\.]/g, '\\$&')
return new RegExp(`^${url}`)
})(),
// Use Netlify subdomain URL
(function() {
if (!process.env.SITE_NAME) return
const name = process.env.SITE_NAME.replace(/[\-]/g, '\\$&')
return new RegExp(`^https?:\/\/${name}\.netlify\.app`)
})()
])
}
// Also manually set externalPaths
if (!this.options.anchorParser?.externalPaths) {
this.options.anchorParser.externalPaths = [
// Don't client-side navigate to Netlify functions
/^\/\.netlify/,
]
}
// Register the vue-routing-anchor-parser module
requireOnce(this, 'vue-routing-anchor-parser/nuxt/module')
}