mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-23 04:09:58 +00:00
Change naming function
This commit is contained in:
@@ -63,10 +63,18 @@ export const convertDataObjectToModel = (data) => {
|
|||||||
return { id, ...object.data };
|
return { id, ...object.data };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getURL = () => {
|
export const getSubdirectoryURL = () => {
|
||||||
const url = window.location.href;
|
const url = window.location.href;
|
||||||
|
|
||||||
const parts = url.split('/');
|
const parts = url.split('/'); // Results: ['http:', '', 'example.com', '']
|
||||||
const lastPart = parts.pop(); // Lấy phần tử cuối cùng trong mảng
|
|
||||||
return lastPart;
|
const subDirectory = parts[3]; // Get subdirectory url only
|
||||||
|
|
||||||
|
// Remove query behind subDirectory
|
||||||
|
const index = subDirectory.indexOf('?');
|
||||||
|
if (index !== -1) {
|
||||||
|
return subDirectory.substring(0, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
return subDirectory;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import RegisterView from './registerView';
|
import RegisterView from './registerView';
|
||||||
import LoginView from './loginView';
|
import LoginView from './loginView';
|
||||||
import { getURL } from '../helpers/helpers';
|
import { getSubdirectoryURL } from '../helpers/helpers';
|
||||||
import { URL } from '../constants/constant';
|
import { URL } from '../constants/constant';
|
||||||
|
|
||||||
export default class View {
|
export default class View {
|
||||||
constructor() {
|
constructor() {
|
||||||
switch (getURL()) {
|
switch (getSubdirectoryURL()) {
|
||||||
case URL.LOGIN:
|
case URL.LOGIN:
|
||||||
this.loginView = new LoginView();
|
this.loginView = new LoginView();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user