Path() {
//分割相对路径
var items = location.pathname.substr(1).split('/')
console.log(
location.protocol,
'---',
location.hostname,
'端口号',
location.port
)
//构建主路径
var mainpath =
"<a href='" +
location.protocol +
'//' +
location.hostname +
':' +
location.port +
'/'
var breadcrumbTrail = '<div class="router">'
var Name
for (var i = 0; i < items.length; i++) {
//结尾的斜杠
if (items[i] == 'html') {
Name = '首页'
} else if (items[i] == 'wuliu') {
Name = '一级'
} else if (items[i] == 'detail') {
Name = '二级'
}
if (items[i].length == 0) break
//将主路径增加到一个新的层次
mainpath += items[i]
//在所有的项之后添加斜杠,最后一项除外
if (i < items.length - 1) mainpath += '/'
//创建面包屑路径部分
//仅对内部项添加箭头
if (i > 0 && i < items.length) breadcrumbTrail += ' > '
//添加面包屑
breadcrumbTrail += mainpath + "'>" + Name + '</a>'
}
breadcrumbTrail += '</div>'
document.getElementById('luyou').innerHTML = breadcrumbTrail
},
原生二级路由方法
于 2022-06-18 10:42:21 首次发布