question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There is no way to use a different router

See original GitHub issue

Environment

Nuxt CLI v3.0.0-27398184.5d7f99b 20:47:58 RootDir: /home/user/js/nuxt3-app 20:47:59 Nuxt project info: 20:47:59


  • Operating System: Linux
  • Node Version: v14.16.0
  • Nuxt Version: 3.0.0-27398184.5d7f99b
  • Package Manager: npm@8.4.0
  • Bundler: Vite
  • User Config: srcDir, buildModules, ssr
  • Runtime Modules: -
  • Build Modules: ~/modules/ionic/index.js

Reproduction

Make ssr: false in nuxt.config.js

Create a plugin like this

import {createRouter, createWebHistory} from "@ionic/vue-router";
import routes from '#build/routes'

export default defineNuxtPlugin((nuxtApp) => {
    const router = createRouter({
        history: createWebHistory("/"),
        routes,
    });
    nuxtApp.vueApp.use(router);
});

The package.json file

{
  "private": true,
  "scripts": {
    "dev": "nuxi dev",
    "build": "nuxi build",
    "start": "node .output/server/index.mjs"
  },
  "dependencies": {
    "@ionic/vue": "^6.0.5",
    "@ionic/vue-router": "^6.0.5"
  },
  "devDependencies": {
    "@nuxtjs/router": "^1.7.0",
    "@types/jest": "^27.4.0",
    "@typescript-eslint/eslint-plugin": "^5.10.2",
    "@typescript-eslint/parser": "^5.10.2",
    "@vue/test-utils": "^2.0.0-rc.18",
    "@vue/vue3-jest": "^27.0.0-alpha.4",
    "babel-jest": "^27.4.6",
    "cypress": "^9.4.1",
    "eslint": "^8.8.0",
    "eslint-plugin-vue": "^8.4.0",
    "jest": "^27.4.7",
    "nuxt3": "latest",
    "ts-jest": "^27.1.3",
    "typescript": "^4.5.5"
  }
}

Describe the bug

With the current implementation there is no way to replace the usage of default vue router. I was trying to use ionic with nuxt 3, couldn’t do it using the router-module. I was getting the following error.

[plugin:vite:import-analysis] Failed to resolve import "../src/router.js" from "virtual:/home/eshan/work/js/nuxt3-app/.nuxt/router.js". Does the file exist?
virtual:[/home/user/js/nuxt3-app/.nuxt/router.js:1:53]()
1  |  import { createRouter as customCreateRouter } from '../src/router.js'
   |                                                      ^
2  |  
3  |

Then I tried to make it as plugin, but I am getting the following error:

bootstrap.mjs:39 Error while mounting app: TypeError: Cannot set property $router of #<Object> which has only a getter
    at Object.install (vue-router.esm-bundler.js:3361:41)
    at Object.router.install (index.js:14:9)
    at Object.use (runtime-core.esm-bundler.js:3809:28)
    at router.js:18:17
    at callWithNuxt (nuxt.mjs:91:20)
    at applyPlugin (nuxt.mjs:48:29)
    at applyPlugins (nuxt.mjs:57:11)
    at async initApp (bootstrap.mjs:28:5)

Additional context

No response

Logs

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
fallsimplycommented, Feb 6, 2022

Nuxt is a web framework not a mobile framework.

Ionic projects can be generated by following the Starting an App guide from the Ionic Vue docs

Good luck with your project!

0reactions
danielroecommented, Sep 20, 2022

We now have the ability to customise all the options to createRouter via https://github.com/nuxt/framework/pull/3485 and https://github.com/nuxt/framework/pull/7129. Allowing an entirely separate router to be provided is not a good idea, I think, because it would need to have the same API as vue-router.

It might be worth checking out https://github.com/danielroe/nuxt-ionic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

So.. You Want to Hook Up a Second Router? - YouTube
What this video is not, is a step by step guide on how to do it. MUSIC: Nana Kwabena - Find Your Way...
Read more >
How to Move Your Router to Another Room
The best way to move your router is to move both your modem and router to the new location. But, if you have...
Read more >
How to Connect One Router to Another to Expand a Network
1. Connect the modem to the first router. Use an Ethernet cable to connect to the WAN port of a router to the...
Read more >
14 Useful Ways to Reuse an Old Router (Don't Throw It Away!)
1. Build a Wireless Repeater ... What if your Wi-Fi network doesn't extend across the full range of your home? Although you might...
Read more >
How to Tell When It's Time to Replace Your Router
If you're lucky, your router's manufacturer keeps an updated list of devices it no longer actively supports. In tech jargon, this is an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found