我有一条如下的路线
路径:'/ board /:type(\ d {2}):subtype(\ d {2}):id(\ d +)'
所以这是这样的
http:// localhost:3000 / board / 112233333333
在上述情况下
11是类型的动态值 (最多两位数)
22是子类型的动态值(最多两位数)
33333333是id的动态值。
有人可以让我知道如何为该文件夹创建一个文件夹结构吗?如果不可能的话,处理这种情况的最佳方法是什么?
我有一条如下的路线
路径:'/ board /:type(\ d {2}):subtype(\ d {2}):id(\ d +)'
所以这是这样的
http:// localhost:3000 / board / 112233333333
在上述情况下
11是类型的动态值 (最多两位数)
22是子类型的动态值(最多两位数)
33333333是id的动态值。
有人可以让我知道如何为该文件夹创建一个文件夹结构吗?如果不可能的话,处理这种情况的最佳方法是什么?
您的网址是
http://localhost:3000/board/112233333333
路线中的最后一个参数必须全部为12位数字(任意12位数字)
112233333333-12位数字
使用
validate()
的_id.vue
检查,如果这条路是一个有效的途径。1.
validate()
方法必须返回true或false2.
params.id
invalidate()
method will hold the id (value in url param) , in your case it is112233333333
3.
/^([0-9]{12,12})$/.test(params.id)
will returntrue
if id (value in url param) has 12 digits else returnfalse
true
- route will be loaded successfullyfalse
- error page will be displayed (404 page not found - because route was not recognized)if true is returned by the validate method then this means the page is allowed to be loaded. Now we have to make use of vuejs life cycle hooks to proceed further.
1.In the
created()
life cycle hook, extract the value from the url usingthis.$route.params.id
2.Split the value
this.$route.params.id
using regex. Use match method to group into the format you need. In your case you have split it into 2,2,8 digits. The regex in below snippet exactly does thatNow you have all the values you need after proper validation. Your can ignore the value in
contents[0]
.Below is the code for testing the approach i have described here.
Place the code in
_id.vue
file and verify the results.Reference https://nuxtjs.org/api/pages-validate