router.js 1.1 KB

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