Router Pinia error: getActivePinia was called with no active Pinia. Did you forget to install pinia
Solution:1. First create the store TS file
import { createPinia } from "pinia";
const pinia = createpinia();
export default pinia;
Instead of the kind of form created in main.ts.
2. Import in Mian.ts
// Alternative to the traditional direct import in main.ts
import { createApp } from "vue"
import App from './App.vue'
import pinia from "./store/store"
const app = createApp(App)
app.use(pinia)
3. Using Pinia in router.ts
import { createRouter, createWebHistory } from 'vue-router'
import pinia from '../store/store'
import { useUser} from "../store/useUser"
const store = useUser(pinia) // Make sure to pass in pinia here
console.log(store)
After that, you can use the methods and properties of the store as you like
Read More:
- How to Solve pinia Error in ts File
- [Solved] Vue3 Install vuetify Error: Error: You cannot call “get” on a collection with no paths.
- How to open a page in a new window by Vue router
- [Solved] Vue-router Error: Navigation cancelled from “/course“ to “/user“ with a new navigation.
- [Solved] To install it, you can run: npm install –save core-js/modules/es.error.cause.js
- [Solved] Vue-cli Error: Module not found: Error: Can‘t resolve ‘vue-router ‘
- Vue-router import Dynamic Module Error [How to Solve]
- Error: Computed property “menuList” was assigned to but it has no setter.
- [Solved] react-router-dom Error: index.js:1 Warning: Functions are not valid as a React child.
- [Solved] Uncaught (in promise) DOMException: Failed to load because no supported source was found.
- [Solved] react-router-dom Error: <NavLink>activeClassName
- [Solved] Uncaught Error: Provide the “history“ option when calling “createRouter()“
- [Solved] vue-roter 4 Error: Error: Invalid route component/Uncaught (in promise) Error: Invalid route component
- [Solved] Vue3 Import element UI error: Uncaught TypeError: Cannot read properties of underfined…
- Solve the problem of repeatedly clicking the same route console in Vue to report an error
- React error boundary (What You Should Know & How to Solve)
- [Solved] Vue3 Configuration routing error: Catch all routes (“*“) must now be defined using a param with a custom regexp.
- [Solved] VUE npm install Error: Module build failed: Error: ENOENT: no such file or directory, scandir
- How to Solve npm-install Command -4048 Error
- Vue Error: Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location