Steven Fukase 4 лет назад
Родитель
Сommit
d914d9c483
1 измененных файлов с 12 добавлено и 8 удалено
  1. 12 8
      src/client/js/components/PageCreateModal.jsx

+ 12 - 8
src/client/js/components/PageCreateModal.jsx

@@ -77,16 +77,20 @@ const PageCreateModal = (props) => {
    * @param {string} paths
    */
   function redirectToEditor(...paths) {
-    // Remove trailing slashes
-    const joinedPath = [...paths].map(str => str.replace(/^\/+|\/+$|\s/g, '')).join('/').replace(/\/$/, '');
+
+    const joinedPath = [...paths]
+      .map(str => str.replace(/^\/+|\/+$|\s/g, ''))
+      .join('/')
+      .replace(/\/$/, '');
+
+    if (!isCreatablePage(joinedPath)) {
+      toastError(new Error('Invalid characters'));
+      return;
+    }
+
     try {
       const url = new URL(joinedPath, 'https://dummy');
-      if (!isCreatablePage(url.pathname)) {
-        toastError(new Error('Invalid characters'));
-        return;
-      }
-      // window.location.href = `${url.pathname}#edit`;
-      console.log(`${url.pathname}#edit`);
+      window.location.href = `${url.pathname}#edit`;
     }
     catch (err) {
       toastError(new Error('Invalid path format'));