router.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }
  39. }
  40. // console.log('router', app.router)
  41. app.router.beforeEach((to, from, next) => {
  42. next()
  43. })
  44. }
  45. }