Skip to content

Commit b398186

Browse files
authored
Add note on using web history mode with Vue Router
1 parent bc5fbbc commit b398186

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/Vue/Resources/doc/index.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ The event ``vue:before-mount`` is called before a component is mounted on the pa
115115
});
116116
117117
.. note::
118-
When using Vue Router, it is recommended to use "hash" (or "memory") history mode,
118+
When using Vue Router, you can use "hash" or "memory" history mode
119119
to prevent your Vue routes from being served through Symfony controllers.
120+
If you want to use web history mode, see :ref:`Web History mode with Vue Router`
120121

121122
The event ``vue:mount`` is called when a component has been mounted on the page:
122123

@@ -141,6 +142,35 @@ The event ``vue:unmount`` is called when a component has been unmounted on the p
141142
} = event.detail;
142143
});
143144
145+
Web History mode with Vue Router
146+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147+
148+
To use "web" history mode with Vue Router, a catch-all route will be needed
149+
which should render the same template and Vue component:
150+
151+
.. code-block:: php
152+
153+
#Route('/survey/{path<.+>}')
154+
public function survey($path = ''): Response
155+
{
156+
// render the template
157+
}
158+
159+
This controller will catch any URL that starts with `/survey`. This prefix can then be
160+
used for all the Vue routes:
161+
162+
.. code-block:: js
163+
164+
const router = VueRouter.createRouter({
165+
history: VueRouter.createWebHistory(),
166+
routes: [
167+
{ path: '/survey/list', component: ListSurveys },
168+
{ path: '/survey/create', component: CreateSurvey },
169+
{ path: '/survey/edit/:surveyId', component: EditSurvey },
170+
],
171+
});
172+
173+
app.use(router);
144174
145175
Backward Compatibility promise
146176
------------------------------

0 commit comments

Comments
 (0)