mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +00:00
Change naming function
This commit is contained in:
@@ -63,10 +63,18 @@ export const convertDataObjectToModel = (data) => {
|
||||
return { id, ...object.data };
|
||||
};
|
||||
|
||||
export const getURL = () => {
|
||||
export const getSubdirectoryURL = () => {
|
||||
const url = window.location.href;
|
||||
|
||||
const parts = url.split('/');
|
||||
const lastPart = parts.pop(); // Lấy phần tử cuối cùng trong mảng
|
||||
return lastPart;
|
||||
const parts = url.split('/'); // Results: ['http:', '', 'example.com', '']
|
||||
|
||||
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 LoginView from './loginView';
|
||||
import { getURL } from '../helpers/helpers';
|
||||
import { getSubdirectoryURL } from '../helpers/helpers';
|
||||
import { URL } from '../constants/constant';
|
||||
|
||||
export default class View {
|
||||
constructor() {
|
||||
switch (getURL()) {
|
||||
switch (getSubdirectoryURL()) {
|
||||
case URL.LOGIN:
|
||||
this.loginView = new LoginView();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user