redirect-module
redirect-module copied to clipboard
feat(module): leverage vue-router redirect
I put new properties in the path
and redirect
rules because the redirection done by the vue-router is different so the user can customize it if necessary.
For example, vue-router does not accept ^/abc
in spa mode, but in universal mode this is acceptable, in spa mode /abc/(:id)
this is acceptable, no longer in universal mode.
This /abc
redirection per example is acceptable in both modes.
Resolve #3
Codecov Report
:exclamation: No coverage uploaded for pull request base (
master@4000dc7
). Click here to learn what that means. The diff coverage is100%
.
@@ Coverage Diff @@
## master #37 +/- ##
=======================================
Coverage ? 100%
=======================================
Files ? 2
Lines ? 37
Branches ? 9
=======================================
Hits ? 37
Misses ? 0
Partials ? 0
Impacted Files | Coverage Δ | |
---|---|---|
lib/module.js | 100% <100%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 4000dc7...f6dcff5. Read the comment docs.
Thanks so far!
I wouldn't differentiate between SPA
and universal
mode. Instead, I'd check whether there is a server running or not (which makes the difference of having serverMiddleware
handling everything or 'falling back' to the vue-router).
Could you give me an example of how you're thinking?
@manniL if change
if (this.options.mode === 'spa') {
to
this.nuxt.hook('generate:before', () => {
What I tested would solve the problem well.
@ricardogobbosouza but then the extended route isn't included in the build bundle / .nuxt/router.js
I think.
@manniL It worked perfectly with the test I did local
I will work on this change and its tests, but we will still have that divergence:
- vue router using path-to-regexp that syntaxically/contextually different from js regex , if we don't move to that and take argument in the same form, it would be difficult to keep route working when 'proxying' to it. https://github.com/nuxt-community/redirect-module/issues/3#issuecomment-430624167
Hmm... right. 🤔 We should make that clear in the README I guess.
@manniL The only way to work in both cases is to use path-to-regexp
on the serverMiddleware
, the same as vue-router
uses and this should probably generate BREAKING CHANGE
What do you think of switching to path-to-regexp
?
Or do we create different options for the vue-router
case as I said earlier https://github.com/nuxt-community/redirect-module/pull/37#issue-263278747
What do you think of switching to path-to-regexp ?
I wrote a serverMiddleware
which redirects using path-to-regexp
: https://github.com/nuxt-community/redirect-module/issues/77#issuecomment-622328769
Hi guys! Is it abandoned? Seems like that without this feature, the module is useless. If only i could help to push it forward?
Due to lack of maintenance I forked that repo with merged client routing (thanks @ricardogobbosouza !) https://github.com/Bravado-network/nuxt-redirects
What I also added:
- permanent: true instead of 301/302 status code (like in next.js redirects) to avoid confusion and mistakes;
- path-to-regexp instead of 2 different scheme for client and server;
- redirect to external urls;