Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quasar Capacitor History/Hashmode #17322

Closed
Excel1 opened this issue Jun 24, 2024 · 2 comments
Closed

Quasar Capacitor History/Hashmode #17322

Excel1 opened this issue Jun 24, 2024 · 2 comments
Labels
bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite kind/bug 🐞 mode/capacitor Qv2 🔝 Quasar v2 issues

Comments

@Excel1
Copy link

Excel1 commented Jun 24, 2024

What happened?

I have developed an app with Quasar using Capacitor. My goal is to connect oidc-client.ts to my app. Everything works fine so far, but in production mode the router uses hashmode, although I forced historymode in the configuration file. In the web browser, history mode is used correctly. However, oidc-client.ts expects history mode because it needs the redirect URLs to extract the token, which is not possible in hashmode from Capacitor to Quasar.

What did you expect to happen?

Quasar with Capacitor should using the same router mode. Is it set to history, then history should be used in the app.

Reproduction URL

https://stackblitz.com/edit/quasarframework-dgzdtc?file=src%2Fpages%2FIndexPage.vue,quasar.config.js

How to reproduce?

  1. Create or choose a Quasar Project
  2. Make sure history-mode is set in quasar.config.js
  3. Add capacitor plattform android
  4. Build App for production and open in Android Studio
  5. Go to Chrome Devtools and inspect app
  6. Watch the location url > hashmode "https://localhost/#/"

Flavour

Quasar CLI with Vite (@quasar/cli | @quasar/app-vite)

Areas

Capacitor Mode

Platforms/Browsers

Android

Quasar info output

Operating System - Linux(6.8.0-31-generic) - linux/x64
NodeJs - 18.18.2

Global packages
  NPM - 9.8.1
  yarn - Not installed
  @quasar/cli - undefined
  @quasar/icongenie - 2.5.4
  cordova - Not installed

Important local packages
  quasar - 2.16.4 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
  @quasar/app-vite - 1.9.3 -- Quasar Framework App CLI with Vite
  @quasar/extras - 1.16.11 -- Quasar Framework fonts, icons and animations
  eslint-plugin-quasar - Not installed
  vue - 3.4.30 -- The progressive JavaScript framework for building modern web UI.
  vue-router - 4.4.0
  pinia - 2.1.7 -- Intuitive, type safe and flexible Store for Vue
  vuex - Not installed
  vite - 2.9.18 -- Native-ESM powered web dev build tool
  eslint - 8.57.0 -- An AST-based pattern checker for JavaScript.
  electron - Not installed
  electron-packager - Not installed
  @electron/packager - Not installed
  electron-builder - Not installed
  register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
  @capacitor/core - 6.1.0 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/cli - 6.1.0 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/android - 6.1.0 -- Capacitor: Cross-platform apps with JavaScript and the web
  @capacitor/ios - Not installed

Quasar App Extensions
  *None installed*

Networking
  Host - WS
  enp42s0 - 192.168.188.20

Relevant log output

No response

Additional context

No response

@Excel1 Excel1 added kind/bug 🐞 Qv2 🔝 Quasar v2 issues labels Jun 24, 2024
@github-actions github-actions bot added bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite mode/capacitor labels Jun 24, 2024
@Excel1
Copy link
Author

Excel1 commented Jun 24, 2024

Does quasar uses different router modes for different deploys? Cause if i force router mode history

  const createHistory = createWebHistory;

it seems to work as it should be

@yusufkandemir
Copy link
Member

@Excel1: Does quasar uses different router modes for different deploys?

Yes, it does:

if (this.#ctx.mode.ssr) {
cfg.build.vueRouterMode = 'history'
}
else if (this.#ctx.mode.cordova || this.#ctx.mode.capacitor || this.#ctx.mode.electron || this.#ctx.mode.bex) {
cfg.build.vueRouterMode = 'hash'
}

Please see https://capacitorjs.com/docs/config#schema:

    /**
     * Configure the local scheme on iOS.
     *
     * [Can't be set to schemes that the WKWebView already handles, such as http or https](https://developer.apple.com/documentation/webkit/wkwebviewconfiguration/2875766-seturlschemehandler)
     * This can be useful when migrating from
     * [`cordova-plugin-ionic-webview`](https://github.com/ionic-team/cordova-plugin-ionic-webview),
     * where the default scheme on iOS is `ionic`.
     *
     * @since 1.2.0
     * @default capacitor
     */
    iosScheme?: string;

    /**
     * Configure the local scheme on Android.
     *
     * Custom schemes on Android are unable to change the URL path as of Webview 117. Changing this value from anything other than `http` or `https` can result in your
     * application unable to resolve routing. If you must change this for some reason, consider using a hash-based url strategy, but there are no guarentees that this
     * will continue to work long term as allowing non-standard schemes to modify query parameters and url fragments is only allowed for compatibility reasons.
     * https://ionic.io/blog/capacitor-android-customscheme-issue-with-chrome-117
     *
     * @since 1.2.0
     * @default https
     */
    androidScheme?: string;

The default "URL" is https://localhost on Android, and capacitor://localhost on iOS. Since iOS uses a different URL scheme, it's impossible to use the history mode. That's why it enforces hash mode. You could ask why Quasar enforces that on Android as well, and the answer would be unification and simplicity.

As a side information, Cordova, Electron, and BEX use the file scheme(e.g., file:///...), so we also enforce hash mode in those modes.

If it works, you can modify the const createHistory = ... part to satisfy your use case. But, don't expect it to work under all cases. Here are some resources I've found about the topic that you might want to check:
https://forum.ionicframework.com/t/redirect-back-to-app-after-oauth2-oidc-login/201056
https://stackoverflow.com/questions/71577408/is-it-possible-to-for-an-ionic5-capacitor3-application-to-complete-an-open-i

So, to sum up, this is not an issue. It's the expected behavior and for a good reason.

@yusufkandemir yusufkandemir closed this as not planned Won't fix, can't repro, duplicate, stale Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-vite kind/bug 🐞 mode/capacitor Qv2 🔝 Quasar v2 issues
Projects
None yet
Development

No branches or pull requests

2 participants