router.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export default ({ app, context, req, store}) => {
  2. if (process.client) {
  3. const { host } = location || {}
  4. const isJob = host.indexOf('job') !== -1
  5. if (isJob) {
  6. window.__NUXT__.routePath = app.context.route.path.replace(/^\/job/, '/')
  7. let jobIndex = app.router.options.routes.filter(v => v.name === 'job')[ 0 ]
  8. let jobDetail = app.router.options.routes.filter(v => v.name === 'job-detail-id')[ 0 ]
  9. let companyList = app.router.options.routes.filter(v => v.name === 'job-company-list-city')[ 0 ]
  10. let companyList2 = app.router.options.routes.filter(v => v.name === 'job-company-city')[ 0 ]
  11. let jobIndexNow = {
  12. name: jobIndex.name,
  13. path: '/*',
  14. component: jobIndex.component
  15. }
  16. let jobDetailNow = {
  17. name: jobDetail.name,
  18. path: '/d/:id?',
  19. component: jobDetail.component
  20. }
  21. let companyListNow = {
  22. name: companyList.name,
  23. path: '/company/list/:city?',
  24. component: companyList.component
  25. }
  26. // let companyListNow2 = {
  27. // name: companyList2.name,
  28. // path: '/company/:city?',
  29. // component: companyList2.component
  30. // }
  31. let jobOrderList = [
  32. jobDetailNow, companyListNow, jobIndexNow
  33. ]
  34. try {
  35. app.router.options.routes.unshift(...jobOrderList)
  36. app.router.matcher.addRoutes(jobOrderList)
  37. } catch ( e ) {
  38. console.log(e)
  39. }
  40. }
  41. // console.log('router', app.router)
  42. app.router.beforeEach((to, from, next) => {
  43. console.log("beforeEach", to, from)
  44. next()
  45. })
  46. }
  47. }