router.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 jobIndexNow = {
  11. name: jobIndex.name,
  12. path: '/*',
  13. component: jobIndex.component
  14. }
  15. let jobDetailNow = {
  16. name: jobDetail.name,
  17. path: '/d/:id?',
  18. component: jobDetail.component
  19. }
  20. let companyListNow = {
  21. name: companyList.name,
  22. path: '/company/list/:city?',
  23. component: companyList.component
  24. }
  25. let jobOrderList = [
  26. jobDetailNow, jobIndexNow, companyListNow
  27. ]
  28. try {
  29. app.router.options.routes.unshift(...jobOrderList)
  30. app.router.matcher.addRoutes(jobOrderList)
  31. } catch ( e ) {
  32. console.log(e)
  33. }
  34. }
  35. // console.log('router', app.router)
  36. app.router.beforeEach((to, from, next) => {
  37. // console.log("beforeEach", to, from)
  38. next()
  39. })
  40. }
  41. }