Skip to content

failed to redirect from '/routePath' to '/routePath/', maybe the problem is about named routes #720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Wangszzju opened this issue Aug 10, 2018 · 2 comments · Fixed by #1269

Comments

@Wangszzju
Copy link

Wangszzju commented Aug 10, 2018

Bug report

Version

0.14.1

Steps to reproduce

  • First,download the git repo of vuepress
  • Secondly,run the command
npm run dev
  • visit the URL http://localhost:8080/config/,OK,it works
  • then, visit the URL http://localhost:8080/config

What is expected?

The page shoule be redirect to http://localhost:8080/config/

What is actually happening?

The page does not show anything.

My Pull Request Here

It's my PR here

Other relevant information

I used the source panel and debug step by step.

It seems that when the router got the url config,it tries to

  // redirect /foo to /foo/
  router.beforeEach((to, from, next) => {
    if (!/(\/|\.html)$/.test(to.path)) {
      next(Object.assign({}, to, {
        path: to.path + '/'
      }))
    } else {
      next()
    }
  })

but the next function had been invoked again and again , and the route.path was still the '/config' rather than '/config/'.

And I uninstall the vuepress@0.14.1 and install the version 0.8.4, and the problem does not exist.

I compared them. The main difference came from the statement, in History.prototype.transitionTo.

var route = this.router.match(location, this.current);

when the version of vuepress is 0.14.1, the path prop in the return value of the match method, is /config, while it's /config/ in 0.8.4. But before the statement is executed, the value of the path prop in the first parameter location,is /config/.

And another diffrence is that the route object has name prop in the version 0.14.1, while it does not in version 0.8.4

I had not read the source code of vue-router and vuepress. But I guess there is something wrong with the name prop of the route object. And I noticed that a route config is created in the dir temp/routes when you run the dev command.

  • Your OS: macOS Sierra 10.12.6
  • Node.js version: 9.8.0
  • Browser version: Chrome 68.0.3440.84
  • Is this a global or local install? local
  • Which package manager did you use for the install? yarn
@meteorlxy
Copy link
Member

It's a known 'bug', or Vuepress is originally designed to have this behavior.

In fact I also think url without trailing slash looks better 👍

@ulivz
Copy link
Member

ulivz commented Aug 11, 2018

Thanks for your interest in VuePress, but it's duplicate of #603, let's move to here to continue discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants