In my router class, I would like to guard if the user search for an entity ID directly by typing in the address bar (rather than clicking through the UI) - "http://application/customer/123". So I need to run the ID against the API to check if the customer exist first, in the 'beforeEnter'.
My problem is:
I'm getting the warning "export 'customerService' was not found in '../services/customerService
.
And I'm also getting the error Home.vue?76f2:17 Uncaught TypeError: _services_customerService__WEBPACK_IMPORTED_MODULE_2__.customerService is not a constructor
when running the page.
Here is my code:
// Path: Project/src/services/customerService.js
export default class customerService {}
// Path: Project/src/router/index.js
import { customerService } from '../services/customerService.js';
const routes = [
{
path: '/customer/:id?',
name:'customer',
component: Customer,
beforeEnter: async (to, from, next) => {
// This could be from trying to access the page by directly typing the URL in the address bar
if (from.name !== "customers") {
var m = new customerService();
var resp = await m.getCustomerById(to.params.id);
} else {
next();
}
},
},
]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…